Express module not found when installed with NPM

后端 未结 14 1538
庸人自扰
庸人自扰 2020-12-22 22:59

When I try to run the app.js file created by express, I get the following error:

$ node app.js

node.js:134
        throw e; // process.nextTick         


        
相关标签:
14条回答
  • 2020-12-22 23:05
    • Install express

      npm install -g express

    • Create a new app

      express your_app

    • cd into app directory

      cd your_app

    • use npm link to resolve modules

      npm link express

    0 讨论(0)
  • 2020-12-22 23:07

    What about NODE_PATH=/usr/local/lib/node_modules in .bashrc or .bash_profile? I think it's the real correct way.

    0 讨论(0)
  • 2020-12-22 23:07

    Set NODE_PATH=NODE_HOME\node_modules.

    I'm using windows 7 and it works fine.

    0 讨论(0)
  • 2020-12-22 23:08

    Finally with Linux a good way to do is to use the command : sudo apt-get install node-express

    But with express 4 we must use express-generator to make app skeleton, install it with 'npm install express-generator -g', and then run 'express myapp' command. see also install express

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

    For all problems with express with a mac computer:

    The solution is:

    1. chown to your user the .npm folder :

      sudo chown -R Webmaste /Users/webmaste/.npm/
      
    2. At your test folder or your folder:

      sudo npm install -g express@2.5.8
      
    3. Invoke express from your actual location:

      /usr/local/share/npm/bin/express
      
    4. sudo cd . && npm install

    5. Finally:

      node app
      

    the final message in the console should look like this:

    Express server listening on port 3000 in development mode

    0 讨论(0)
  • 2020-12-22 23:17

    Use local installs for require(), and global installs for command-line apps.

    If you need both, use the npm link command.

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