Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

typing npm commands in the node repl #2931

Closed
isaacs opened this issue Mar 14, 2012 · 8 comments
Closed

typing npm commands in the node repl #2931

isaacs opened this issue Mar 14, 2012 · 8 comments

Comments

@isaacs
Copy link

isaacs commented Mar 14, 2012

New users often start up node, and begin typing npm commands into the repl.

There are a few approaches we can take here:

  1. LOL n00b! SYNTAX ERROR! TAKE THAT! HAHA! This is what we're doing now. I don't think it's friendly enough.
  2. A message telling the user that they need to run npm commands in their regular command prompt, not in the node repl. (What's a relp? I thought this WAS the node command? Why can't it run npm? HALP!) So, the message has to be very clear, and addressed to a brand new user who lacks command line knowhow.
  3. Actually make npm commands work from the node repl. (Crazy talk! I'm not even sure how that would work.)
@TooTallNate
Copy link

Both 2 and 3 will require intercepting the repl command and sniffing for an npm command. Here's a proof-of-concept:

 ~ (master)  node
> var e = module.exports.repl.eval
undefined
> module.exports.repl.eval = function (c) {
... if (/^.npm/.test(c)) {
..... console.error('got npm command!')
..... } else {
..... return e.apply(this, arguments)
..... } }
[Function]
> var t = 'test'
undefined
> npm install express
got npm command!

undefined
> t
'test'
> .exit

@isaacs
Copy link
Author

isaacs commented Mar 14, 2012

Yeah, I had this patch:

diff --git a/lib/repl.js b/lib/repl.js
index 4ce849a..4eeea14 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -165,6 +165,13 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) {
     var skipCatchall = false;
     cmd = trimWhitespace(cmd);

+    if (cmd.match(/^npm .+/) && !self.bufferedCmd) {
+      self.outputStream.write('npm should be run in the regular ' +
+                              'command prompt, not in a node repl.\n');
+      self.displayPrompt();
+      return
+    }
+
     // Check to see if a REPL keyword was used. If it returns true,
     // display next prompt and return.
     if (cmd && cmd.charAt(0) === '.') {

But I think the message can be improved.

@isaacs
Copy link
Author

isaacs commented Mar 14, 2012

Also, it'd be cool to at least investigate option 3 at some point. Note that node.exe runs in C:\Program Files (x86)\nodejs\ by default on win32, so for npm to function properly, that should probably move to $HOME (or whatever it's called on Windows).

@OrangeDog
Copy link

You can't install executables into C:\Documents and Settings..., people will invariably delete them without thought.

@piscisaureus
Copy link

I vote for option 2

@lfortin
Copy link

lfortin commented May 22, 2012

I also vote for option 2.

@isaacs
Copy link
Author

isaacs commented Jun 17, 2012

Fixed on master

$ ./node
> npm ls
npm should be run outside of the node repl, in your normal shell.
(Press Control-D to exit.)

@isaacs isaacs closed this as completed Jun 17, 2012
@mperez-bluechip
Copy link

I get the same error message on Windows 7. I tried various options and google it till I started seeing stars. I know there's something in my approach to this problem that's not right or I am misunderstanding how node.js and mongojs communicate. Well, at least I have MongoDB running on the default localhost 27017. Just need to access mongojs and will be over the hump.

richardlau pushed a commit to ibmruntimes/node that referenced this issue Sep 23, 2015
Notable changes

* buffer: Fixed a bug introduced in v4.1.0 where allocating a new
  zero-length buffer can result in the next allocation of a TypedArray
  in JavaScript not being zero-filled. In certain circumstances this
  could result in data leakage via reuse of memory space in
  TypedArrays, breaking the normally safe assumption that TypedArrays
  should be always zero-filled. (Trevor Norris) nodejs#2931.
* http: Guard against response-splitting of HTTP trailing headers
  added via response.addTrailers() by removing new-line ([\r\n])
  characters from values. Note that standard header values are already
  stripped of new-line characters. The expected security impact is low
  because trailing headers are rarely used. (Ben Noordhuis) nodejs#2945.
* npm: Upgrade to npm 2.14.4 from 2.14.3, see release notes for full
  details (Kat Marchán) nodejs#2958
  - Upgrades graceful-fs on multiple dependencies to no longer rely on
    monkey-patching fs
  - Fix npm link for pre-release / RC builds of Node
* v8: Update post-mortem metadata to allow post-mortem debugging tools
  to find and inspect:
  - JavaScript objects that use dictionary properties
    (Julien Gilli) nodejs#2959
  - ScopeInfo and thus closures (Julien Gilli) nodejs#2974
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants