I can't get npm modules to work with require?

Go To StackoverFlow.com

0

I see other questions but I can't really find an answer to make it work. So here is:

node 0.6.6 npm 1.1.15 win7 64bit

What I've done:

  • Installed node "C:\Program Files (x86)\nodejs"
  • Installed npm extracted to "C:\Program Files (x86)\nodejs"
  • run from cmd: npm install express; // installed successfully (also installed with -g, global)
  • created a folder named express in "C:\Users\Totty\node_modules" with some content
  • created my app:

    var app = require('express').createServer();

    app.get('/', function(req, res){ res.send('hello world'); });

    app.listen(3000);

  • run my app: node "D:\Totty\NodeJS\projects\express01"

  • got the error: Cannot find module 'express'

node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ Error: Cannot find module 'express' at Function._resolveFilename (module.js:334:11) at Function._load (module.js:279:25) at Module.require (module.js:357:17) at require (module.js:368:17) at Object. (D:\Totty\NodeJS\projects\express01\main.js:2:11) at Module._compile (module.js:432:26) at Object..js (module.js:450:10) at Module.load (module.js:351:31) at Function._load (module.js:310:12) at Array.0 (module.js:470:10)

I think I have to "say" to my script/node to look into the "C:\Users\Totty\node_modules" folder but I don't know how...

thanks for your help!

2012-04-03 22:52
by Totty.js
http://stackoverflow.com/questions/15471965/what-will-be-the-difference-in-requiremypackage-js-and-requiremypackage/15471995#1547199 - Amol M Kulkarni 2013-03-26 05:28


0

Try installing it locally in your app folder:

cd D:\Totty\NodeJS\projects\express01
npm install express
2012-04-04 08:15
by mihai
ok, I will try. Here at work I've done the same steps but it works, saves data in the users folder and it works with no error. Here I have win vista 32 bit - Totty.js 2012-04-04 08:32
now I think it's always better to put all dependencies in your package.json and then run "npm install" from the project roo - Totty.js 2012-06-02 20:45
Ads