node.js : install module locally | globally

Trabla: install module locally | globally

Solving:

---------------------------------

1) Install locally at the root of your project: if you want use module in your app ,
using require('whatever')

npm install when
where "when" - module name

Example installation output in command line

npm http GET https://registry.npmjs.org/when
npm http 304 https://registry.npmjs.org/when
npm http GET https://registry.npmjs.org/when/-/when-2.7.0.tgz
npm http 200 https://registry.npmjs.org/when/-/when-2.7.0.tgz
when@2.7.0 node_modules\when


Example of error that shows local install needed
module.js:340
    throw err;
          ^
Error: Cannot find module 'when'
    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 Object.<anonymous> (C:\nodejs_projects\ghost\core\index.js:5:17)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

---------------------------------

2) Install globally: if you want to use in  shell, on the command line. Binaries are added to PATH environment variable.

To install  npm module globally use flag -g flag:
npm install -g when

---------------------------------


No comments:

Post a Comment