为什么Node.js控制台中没有下划线模块?

GSt*_*Sto 6 node.js underscore.js

我运行以下代码来安装下划线js模块:

npm install -g underscore
Run Code Online (Sandbox Code Playgroud)

然后我尝试通过节点控制台访问它,但是我收到以下错误:

node
> __ = require('underscore');
Error: Cannot find module 'underscore'
  at Function.Module._resolveFilename (module.js:338:15)
  at Function.Module._load (module.js:280:25)
  at Module.require (module.js:362:17)
  at require (module.js:378:17)
  at repl:1:6
  at REPLServer.self.eval (repl.js:109:21)
  at rli.on.self.bufferedCmd (repl.js:258:20)
  at REPLServer.self.eval (repl.js:116:5)
  at Interface.<anonymous> (repl.js:248:12)
  at Interface.EventEmitter.emit (events.js:96:17)
Run Code Online (Sandbox Code Playgroud)

为什么这个例子不起作用?

Jav*_*avo 6

我真的不知道为什么,但它确实失败了(当你在全球范围内安装下划线时).

如果你在没有-g的情况下安装它,它应该工作(但是,请注意,因为'_'已被Node REPL用来保存上一次操作的结果,如下所述: 将Underscore模块与Node.js一起使用

你真的需要全球安装吗?