Node.js Error: Cannot find module express

前端 未结 15 1388
情话喂你
情话喂你 2020-12-22 18:56

I wrote my first node.js app, but it can\'t find express library:

C:\\ChatServer\\Server>node server.js

module.js:340
    throw err;
          ^
Error: C         


        
相关标签:
15条回答
  • 2020-12-22 19:14

    go to your application directory and install the express module using the below command npm install express --save then list the all install module using the below command npm ls you will see all the locally install modules.

    0 讨论(0)
  • 2020-12-22 19:16

    For me it worked when installed express locally with --save option as follow:

    $ npm install express --save
    
    0 讨论(0)
  • 2020-12-22 19:17

    I'm not proud sharing this, but in my case I had:

     require('express.handlebars')
    
     //and the correct form is:
     require('express-handlebars'); //Use dash instead.
    
    0 讨论(0)
  • 2020-12-22 19:19

    Given you have installed node on your system, install Express locally for your project using the following for Windows:

    npm install express
    

    or

    npm install express --save
    

    You might give it global access by using:

    npm install -g express --save
    
    0 讨论(0)
  • 2020-12-22 19:22

    Golo have explain well the solution, but I might add a clarification:
    sometimes node modules are installed in

    /usr/local/lib/node_modules
    

    and when you launch node blabla.js modules are searched in

    /lib
    

    So a solution is to create a symbolic link:

    sudo ln -s /usr/local/lib/node_modules/ /lib/node_modules
    
    0 讨论(0)
  • 2020-12-22 19:24

    You need to install Express locally into the context of your application (node_modules folder):

    $ npm install express
    

    The reason for this is that applications always look in their local context for any dependencies. The global installation is only for setting up system-wide available binaries, such as unit test runners or bootstrappers or things like that.

    With Express, when you install it globally, you get an express binary that can bootstrap an application for you. For more information, type

    $ express --help
    

    So, to answer your final question: YES, you need to install it without -g.

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