32

I am kind of new to node.js. I installed node fine and it works. I can run the node command in the terminal as well as the node package manager command(npm). Working on a Mac by the way. So I installed express globally with the following command:

sudo npm install -g express

After I was done installing it globally I installed it in a small folder where I am working on a project.

sudo install express

That gave me a node_modules folder inside of my site folder. After I was done that I went to install stylus using the express command and I got the error that express is not a command.

express -c stylus

Can anyone shed some light on this issue? I also tried to link the global express to the folder where I am working on the project using the following command:

sudo npm link express

The terminal said that this command ran, but I still cannot run the express command.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Max Baldwin
  • 3,404
  • 3
  • 26
  • 40
  • 1
    What version of Express do you have installed? If it's v4 rc or higher, I believe you need another module (http://expressjs.com/guide.html#executable) – Traveling Tech Guy Apr 09 '14 at 22:58
  • Have you tried to reload the terminal window or at least use [`source`](http://ss64.com/osx/source.html) in it? – Ricardo Souza Apr 09 '14 at 22:58
  • Running the express generator helped. I can now run the express command. I also ran express -c stylus and that seemed to work. If I run into anything else I will let you know, but I think I am good for now. Thanks! – Max Baldwin Apr 09 '14 at 23:05
  • possible duplicate of [Express command not found](http://stackoverflow.com/questions/23002448/express-command-not-found) – José Luis Jun 01 '14 at 17:02

6 Answers6

89

Thanks for asking questions on this one. I found that running express-generator instead of just express fixed the problem. The following code in the terminal worked.

sudo npm install -g express-generator

Thanks again,

Max Baldwin
  • 3,404
  • 3
  • 26
  • 40
8

If your express binary keeps doing nothing. Install node-legacy:

sudo apt-get install nodejs-legacy

Quentin Rufin
  • 135
  • 2
  • 11
  • Did you find this useful when you were having trouble installing express or was this a specific use case? – Max Baldwin Dec 19 '14 at 12:01
  • Yes, this solved my problem. For some reasons, running 'sudo npm install -g express-generator' did not solve my problem. The express command did nothing. – Quentin Rufin Dec 22 '14 at 14:48
  • Were you running an older version of Node? What version of Node are you running. Did you change anything in your install of Node? – Max Baldwin Dec 22 '14 at 23:17
  • Express was doing nothing and it solved it. I have node.js v0.10.15 on ubuntu 13.04. – Arnaud A Jan 20 '15 at 20:23
  • Just a note, this does work but the question was specifically aimed at Mac's Terminal not Linux's Terminal. – Agustin Nov 25 '15 at 00:56
5

on ubuntu 14.04 nodejs 0.10 express did not work on terminal, though

sudo apt-get install nodejs-legacy

made it to work.

djsharma
  • 63
  • 1
  • 7
3

I faced similar issue. I tried all the solutions mentioned here. However couldn't get my problem solved.

This happens when location of express and nodejs is not same.

Issue arises when Node is installed using homebrew.

Just use this command export PATH=/usr/local/share/npm/bin:$PATH

NOTE: replace path with the path of express.

Follow this link for help.

0

Make sure you have package.json & index.js files. And instaled express-generator with -g tag. If still getting error use like ex:npx express --view=pug myapp --git

karna
  • 1
  • 1
0

I fixed this on my mac by forcing my user to own /usr/local/lib and running the command to install express-generator globally:

sudo chown -R $USER /usr/local/lib

then:

npm install -g express-generator

After this you can go ahead and run your express commands:

express -h

avlnx
  • 676
  • 1
  • 6
  • 19