node.js, Error: Cannot find module 'express'

后端 未结 18 1765
情话喂你
情话喂你 2020-12-02 08:57

I am new to Node.js, try to learn express to build my first web application. I got stuck on my very first sample code and need some help to get it running. Before I post th

相关标签:
18条回答
  • 2020-12-02 09:26

    Digging up an old thread here BUT I had this same error and I resolved by navigating to the directory my NodeApp resides in and running npm install -d

    0 讨论(0)
  • 2020-12-02 09:29
    D:\learn\Node.js\node app.js
    module.js:549
        throw err;
        ^
    
    Error: Cannot find module 'body-parser'
        at Function.Module._resolveFilename (module.js:547:15)
        at Function.Module._load (module.js:474:25)
        at Module.require (module.js:596:17)
        at require (internal/module.js:11:18)
    

    Sometimes version not match with package.json Fixed the problem by checking the package.json then use the following commands: npm install body-parser@1.13.2 it resolved for me.

    0 讨论(0)
  • 2020-12-02 09:32

    After you do express in your terminal, then do

     npm install
    

    To install all the dependencies.

    Then you can do node app to run the server.

    0 讨论(0)
  • 2020-12-02 09:34

    npm install from within your app directory will fix the issue as it will install everything required

    0 讨论(0)
  • 2020-12-02 09:35

    You have your express module located in a different directory than your project. That is probably the problem since you are trying to require() it locally. Try moving your express module from /Users/feelexit/nvm/node_modules/express to /Users/feelexit/WebstormProjects/learnnode/node_modules/express. This info can give you more detail about node_module file structures.

    0 讨论(0)
  • 2020-12-02 09:40

    for this scenario run npm install express command using your cmd prompt for the respective folder where you want to run the program. Example I want to run the express module program server.js in F:\nodeSample. So run "npm install express" in that particular folder then run server.js

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