Alex Rivera | Logout

Express module not found when installed with NPM

Asked 2011-05-07T07:08:38.483
47

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?

Edit
Report

2 Answers

20

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.

answered 2012-08-09T16:05:49.250
0

For all problems with express with a mac computer:

The solution is:

  1. chown to your user the .npm folder :

    sudo chown -R Webmaste /Users/webmaste/.npm/
    
  2. At your test folder or your folder:

    sudo npm install -g express@2.5.8
    
  3. Invoke express from your actual location:

    /usr/local/share/npm/bin/express
    
  4. sudo cd . && npm install

  5. Finally:

    node app
    

the final message in the console should look like this:

Express server listening on port 3000 in development mode

answered 2013-01-28T16:42:42.513

Your Answer