When I try to run the app.js file created by express, I get the following error:
$ node app.js
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'express'
at Function._resolveFilename (module.js:320:11)
When I type in 'express --version' I get a return statement of 2.3.3. I used npm to install express. I had to manually make npm using these instructions:
git clone http://github.com/isaacs/npm.git
cd npm
sudo make install
The error is Error: Cannot find module 'express'
.
Do I need to do something after installing npm and express in order to make express see the modules created by npm?
My node is version: 0.4.6 My express is version: 2.3.3 My npm is version: 1.0.6
Express is installed globally. I used the -g flag to install it.
Edit: When I try "node -e require.paths" I get:
[ '/home/user/.node_modules', '/home/user/.node_libraries', '/usr/local/lib/node' ]
So, node isn't detecting the npm installation. How do I get node to detect the npm installation?
On Ubuntu 12.04 you have to add the
export NODE_PATH=/usr/local/lib/node_modules
to your /.bashrc to use globally installed modules.What about
NODE_PATH=/usr/local/lib/node_modules
in .bashrc or .bash_profile? I think it's the real correct way.Install express
npm install -g express
Create a new app
express your_app
cd into app directory
cd your_app
use npm link to resolve modules
npm link express
It looks like the easiest way to do this is to run
npm install
from your app's folder. This tells npm to hook everything up.It's the last instruction after
express <appname>
:Finally with Linux a good way to do is to use the command :
sudo apt-get install node-express
But with express 4 we must use express-generator to make app skeleton, install it with 'npm install express-generator -g', and then run 'express myapp' command. see also install express
Set
NODE_PATH=NODE_HOME\node_modules
.I'm using windows 7 and it works fine.