140
votes

For some reason after installing Express globally on my machine with npm install -g express if I cd into a directory and try to run express I get the following error:

express: command not found. 

Even if I run it with sudo I still get the same output. I've tried multiple different solutions to this problem and nothing has worked. I had installed node via homebrew which some threads on Stack Overflow indicated might have been a problem so I completely uninstalled node and reinstalled via the installer on nodejs.org (I'm now running v0.10.26) and the problem still persists.

If I go into my /usr/local/lib/node_modules Express is in there but within /usr/local/bin there is nothing regarding Express. I'm not sure if that's a problem or not but considering there are binaries for other globally installed node packages in that directory I'm thinking there may be something wrong there.

This is the exact output I get when I install:

npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/accepts/1.0.0
npm http GET https://registry.npmjs.org/type-is/1.0.0
npm http GET https://registry.npmjs.org/range-parser/1.0.0
npm http GET https://registry.npmjs.org/cookie/0.1.0
npm http GET https://registry.npmjs.org/fresh/0.2.2
npm http GET https://registry.npmjs.org/buffer-crc32/0.2.1
npm http GET https://registry.npmjs.org/send/0.2.0
npm http GET https://registry.npmjs.org/methods/0.1.0
npm http GET https://registry.npmjs.org/cookie-signature/1.0.3
npm http GET https://registry.npmjs.org/utils-merge/1.0.0
npm http GET https://registry.npmjs.org/merge-descriptors/0.0.2
npm http GET https://registry.npmjs.org/escape-html/1.0.1
npm http GET https://registry.npmjs.org/serve-static/1.0.1
npm http GET https://registry.npmjs.org/qs/0.6.6
npm http GET https://registry.npmjs.org/path-to-regexp/0.1.2
npm http GET https://registry.npmjs.org/parseurl/1.0.1
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/cookie/0.1.0
npm http 304 https://registry.npmjs.org/type-is/1.0.0
npm http 304 https://registry.npmjs.org/buffer-crc32/0.2.1
npm http 304 https://registry.npmjs.org/methods/0.1.0
npm http 304 https://registry.npmjs.org/accepts/1.0.0
npm http 304 https://registry.npmjs.org/range-parser/1.0.0
npm http 304 https://registry.npmjs.org/cookie-signature/1.0.3
npm http 304 https://registry.npmjs.org/fresh/0.2.2
npm http 304 https://registry.npmjs.org/serve-static/1.0.1
npm http 304 https://registry.npmjs.org/qs/0.6.6
npm http 304 https://registry.npmjs.org/utils-merge/1.0.0
npm http 304 https://registry.npmjs.org/merge-descriptors/0.0.2
npm http 304 https://registry.npmjs.org/escape-html/1.0.1
npm http 304 https://registry.npmjs.org/path-to-regexp/0.1.2
npm http 304 https://registry.npmjs.org/parseurl/1.0.1
npm http 304 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/send/0.2.0
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/send/0.1.4
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/negotiator
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/send/0.1.4
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/fresh/0.2.0
npm http 304 https://registry.npmjs.org/negotiator
npm http 304 https://registry.npmjs.org/range-parser/0.0.4
npm http 304 https://registry.npmjs.org/fresh/0.2.0
[email protected] /usr/local/lib/node_modules/express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected])
4

4 Answers

366
votes

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

34
votes

You need to run:

npm install -gd express-generator

The original express with cli, now the cli split into separate express-generator package. Originally generated by the project is running express node app.js, because httpserver relevant code in app.js, and now this part of the code to the project directory bin/www below, app.js retain only achieve app logic code, you need to run the bin/www. Just a very simple application and refinement package dependency version changes.

3
votes

I was having this challenge for a number of days. After deep search, I learned that one has to read every available resource especially from the parent source [in this case EXPRESSJS.COM]. Here is a quick fix.

Beginning with version 4.0+ you don't necessarily need to install express-generator if you are running Node 8.2+. Simply run

npx express-generator

The express-generator will run just the way it runs when you run:express

For more details see Getting Started

Happy reading and research hours.

2
votes

I have been recently trying to install express-generator , however it would give out ,

$ zsh : command not found : express

It was after i did

$ sudo npm install -g express
$ sudo npm install -g express-generator

But then , i saw the console log of the npm install commnand

/usr/local/Cellar/node/13.1.0/bin/express -> /usr/local/Cellar/node/13.1.0/lib/node_modules/express-generator/bin/express-cli.js

which gave a hint that the executable express is in the bin folder.

So the solution is : Open up ~/.zshrc or ~/.bashrc and export the path as follows:

export PATH=/usr/local/Cellar/node/13.1.0/bin:$PATH

It works now.