express command not found in bash after installing it with npm


express command not found in bash after installing it with npm

just installed new ubuntu vm to test around with node
installed things in this order:

now, trying to create a new app i noticed express cannot be used in the shell.
express -v returns
express: command not found
i installed npm like this
curl | sudo sh

and i installed express this way
npm install express

any ideas?


Solution 1:

npm install express -g

You need to install it globally.

Npm 1.0 installs modules locally by default. So the bash executable lives in /node_modules/bin/. You can add that folder to PATH or you can just install express globally so that it’s picked up by PATH

Solution 2:

Starting from express 4.00 you also need to install express generator with:

npm install -g express-generator

Only after this will you be able to run express as a command!

For confirmation see: – Migrating to Express 4

Solution 3:

I had this problem and was installing node via Homebrew. The problem was being caused by Homebrew.

So I did:

brew uninstall node

and then installed node using the installer on the site.

Then I ran:

npm install -g express

And voila no problems.

Solution 4:

With the release of Express 4.0.0 it looks like you need to do sudo npm install -g express-generator.

Solution 5:

EDIT 2017-06-29: this answer is 6+ years old, but still gets votes/traffic. Instead (for any new users with problems) I’d trust both NODE_PATH official doc and its corresponding bit about REPL usage before this answer.

Quite similar to this issue, node was not finding my global express install, so a require('express') statement would fail.

What fixed this for me, when a global install wasn’t being picked up by node was making sure NODE_PATH env. variable was is set correctly.
On Ubuntu 11.04, with node version 0.5.0-pre, the paths me were:


So, to clarify you might want to export the above env. variable, or you can just test the above values out by doing:

NODE_PATH=/usr/local/lib/node_modules:/usr/local/lib/node node ./you_app.js

Solution 6:

I had to do a combination of things:

  1. From node.js modules path:

    echo 'export NODE_PATH="'$(npm root -g)'"' >> ~/.bash_profile && . ~/.bash_profile

    This sets the file path in bash profile (can be viewed using nano .bash_profile

  2. Slightly modified from Raynos (above) since I needed sudo:

    sudo npm install express -g
  3. Slightly modified from Fazi (above) since I needed sudo:

    sudo npm install -g express-generator


run `DEBUG=myapp:* npm start`