express command not found in bash after installing it with npm

后端 未结 7 1308
自闭症患者
自闭症患者 2020-12-23 11:53

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

node
mongodb-server
npm
express
mongoose

now, trying

相关标签:
7条回答
  • 2020-12-23 12:32

    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
      

    TEST YOUR APPLICATION:

    run `DEBUG=myapp:* npm start`
    

    Ref: http://expressjs.com/en/starter/generator.html

    0 讨论(0)
  • 2020-12-23 12:36

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

    0 讨论(0)
  • 2020-12-23 12:38

    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.

    0 讨论(0)
  • 2020-12-23 12:39

    IF you are running windows:

    export NODE_PATH="C:\Users\IMarek\AppData\Roaming\npm\node_modules"
    
    0 讨论(0)
  • 2020-12-23 12:41

    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

    0 讨论(0)
  • 2020-12-23 12:42

    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

    0 讨论(0)
提交回复
热议问题