3

Setup:

I have NodeJS installed on my system (C) drive on a Windows 8 x64 machine. I have QUnit installed globally via npm:

npm install qunit -g

The problem:

If I attempt to reference QUnit with:

var q = require('qunit');

while running NodeJS from any directory on the C drive, everything works as expected. However, when I run it from my projects directory which resides on my secondary E drive, Node cannot find my globally installed package:

Error: Cannot find module 'qunit'
    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:9
    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)

Is there some other configuration I'm missing to be able to use globally installed packages while running NodeJS from my secondary drive? Is this just unsupported? I'd like to not have to locally install them and check them into source control, but it is a backup option if global packages do not work from secondary drives.

Steve Danner
  • 21,818
  • 7
  • 41
  • 51
  • @Chase, Thanks, yes I did. That's what I meant by 'globally'. I updated the question to include my qunit installation command to be more clear. – Steve Danner Apr 01 '13 at 14:47
  • My fault I must have missed that part =) If you're wanting to use `require()` then you'll want to install it locally. I've added an answer below. Hope it helps. – Chase Apr 01 '13 at 14:54

1 Answers1

4

https://npmjs.org/doc/folders.html

  • Local install (default): puts stuff in ./node_modules of the current package root.
  • Global install (with -g): puts stuff in /usr/local or wherever node is installed.
  • Install it locally if you're going to require() it.
  • Install it globally if you're going to run it on the command line.
  • If you need both, then install it in both places, or use npm link.

To do this you may want to look into creating a package.json file. Which should include all dependencies for a given project. Then you should be able to run npm install to install all the given dependencies for your project.

There's a related answer here about creating a package.json file.

Community
  • 1
  • 1
Chase
  • 29,019
  • 1
  • 49
  • 48
  • Thanks @Chase! The line in bold is what I needed. I'll check the local module folders into source control and be done with it then. – Steve Danner Apr 01 '13 at 17:41