express command not found in bash after installing it with npm
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: ExpressJS.com - 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 nodejs.org site.
Then I ran:
npm install -g express
And voila no problems.
Solution 4
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:
NODE_PATH=/usr/local/lib/node_modules:/usr/local/lib/node
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 5
With the release of Express 4.0.0 it looks like you need to do sudo npm install -g express-generator.
Related videos on Youtube
Sander
I am a Belgian web developer working on modern websites and applications in JavaScript/NodeJS most of the time. Running a team of ~25 enthusiastic webdevelopers specialised in JavaScript at [Studio Hyperdrive][1]. Since april 2008 I started working with and on the open source Umbraco CMS written in C#.NET. In january 2009 I started experimenting with JavaScript beyond the basic use of a simple jQuery plugin in a single html page, ranging from small web applications, to large codebases with entire Javascript Frameworks like BackboneJS, AngularJS, Angular, ReactJS, NodeJS, ...
Updated on July 09, 2022Comments
-
Sander almost 2 years
just installed new ubuntu vm to test around with node installed things in this order:
node mongodb-server npm express mongoose
now, trying to create a new app i noticed express cannot be used in the shell.
express -v
returns express: command not foundi installed npm like this
curl http://npmjs.org/install.sh | sudo sh
and i installed express this way
npm install express
any ideas?
-
Anja Ishmukhametova about 10 yearsnpm install -g express-generator , and cd myapp && npm install, expressjs.com/guide.html
-
-
Edward M Smith almost 13 yearsYou can also run scripts through npm by adding a "scripts" object to your package.json, and doing, "$ npm run-script scriptname". NPM adds the various bin directories in the local package repo to the path before running the script:
-
hippietrail about 11 yearsWindows doesn't have
export
. If you are referring to cygwin or mingw or something like that you should probably make it explicit. -
Gilman almost 11 years+1 to add the scripts object to package.json and use
npm run-script scriptname
- this keeps your global space clear and allows you to more accurately test your production environment when in dev. -
Tommz almost 10 yearsFinally! This should be accepted as good answer from now on. I even had express in my PATH variable and nothing was working. Thanks @Fazi.
-
Mirko almost 10 yearsTrue, this is the only way
-
michaelAdam over 9 yearsDo you have any idea why this just wouldn't work for me? I run sudo npm install -g express-generator and it installs to usr/bin but I cannot use express. I type "express test" and nothing happens. It just returns to the next line.
-
IQAndreas over 9 yearsAlthough correct, how is this answer different from the answer already given by Fazi? stackoverflow.com/a/23266782/617937
-
g07kore almost 8 yearsactually this is the best answer.
-
s_h over 7 yearsthis should be the answer