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
I installed gulp
and when I ran this gulp
command in the command line I got a gulp: command not found
error. It appeared that it installed gulp
in my local folder that is /home/YOURUSERNAME/.node/lib/node_modules
and not in the global npm
folder.
You can check npm
root folder by running this command: npm root -g
, which was returning my personal directory /home/YOURUSERNAME/.node/lib/node_modules
and not the expected /usr/local/lib/node_modules
.
You can fix this by running npm config set prefix /usr/local
command.
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>
:
...
dont forget to install dependencies:
$ cd <appname> && npm install
It appears that while npm had been updated to install global modules into /usr/local/lib/node_modules
, Node's own require.paths
does not yet reflect this change.
There are two reasonable solutions:
Add the following code to the top of your application:
require.paths.push('/usr/local/lib/node_modules');
Pro: non-invasive, easy to add
Con: requires discipline, future versions of node will restrict access to require.paths
As root, execute:
ln -s /usr/local/lib/node_modules /usr/local/lib/node
Pro: reasonably non-invasive
Con: requires root, modifies linux fs, might not survive system updates
I had the same problem. This worked for me though:
Seems like npm (now?) installs node modules to /usr/local/lib/node_modules/
and not /usr/local/lib/node/
What I did was simply to copy everything from node_modules to node: sudo cp -r /usr/local/lib/node_modules/* usr/local/lib/node/
and now it seems to be working for me.
Hope this helps you :-)
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.
for mac users
cd /usr/local/lib/node
sudo ln -s ../node_modules/* ./$1