typing npm commands in the node repl #2931

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

Projects

None yet

6 participants

@isaacs
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

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
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
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

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

@piscisaureus
Member

I vote for option 2

@lfortin
lfortin commented May 22, 2012

I also vote for option 2.

@isaacs
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 Jun 17, 2012
@mperez-bluechip

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.

@joaocgreis joaocgreis pushed a commit to janeasystems/node-v0.x-archive that referenced this issue Sep 23, 2015
@rvagg rvagg 2015-09-22, Version 4.1.1 (Stable) Release
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) #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) #2945.
* npm: Upgrade to npm 2.14.4 from 2.14.3, see release notes for full
  details (Kat Marchán) #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) #2959
  - ScopeInfo and thus closures (Julien Gilli) #2974

PR-URL: nodejs/node#2995
4a6f1fe
@richardlau richardlau pushed a commit to ibmruntimes/node that referenced this issue Sep 23, 2015
@rvagg rvagg 2015-09-22, Version 4.1.1 (Stable) Release
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) #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) #2945.
* npm: Upgrade to npm 2.14.4 from 2.14.3, see release notes for full
  details (Kat Marchán) #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) #2959
  - ScopeInfo and thus closures (Julien Gilli) #2974
ab55b45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment