I'm trying to play with d3 (and successfully did earlier somehow?) in node. So I did
npm install -g d3
which works great. Let's check:
$ npm list -g d3
/usr/local/lib
└── [email protected]
great. Let's make sure I have the package right:
$ grep name /usr/local/lib/node_modules/d3/package.json
"name": "d3",
Great. So try to require it:
$ node
var d3 = require('d3');
Error: Cannot find module 'd3'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at repl:1:10
at REPLServer.self.eval (repl.js:110:21)
at repl.js:249:20
at REPLServer.self.eval (repl.js:122:7)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
Nope! What gives?
You can't
require()
globally installed modules by default (without mucking with special environment variables and such). If you instead donpm install d3
,require('d3')
should work from the REPL within the current working directory.