-
Notifications
You must be signed in to change notification settings - Fork 7.3k
typing npm commands in the node repl #2931
Comments
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 |
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. |
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). |
You can't install executables into C:\Documents and Settings..., people will invariably delete them without thought. |
I vote for option 2 |
I also vote for option 2. |
Fixed on master
|
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. |
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
New users often start up node, and begin typing npm commands into the repl.
There are a few approaches we can take here:
The text was updated successfully, but these errors were encountered: