Node.js Error: Cannot find module express

前端 未结 15 1386
情话喂你
情话喂你 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:02

    I hit the same problem. I had express installed globally at /usr/local/bin/. When I do 'npm install', express was not created in node_modules of local directory.

    1. Check if you have file name .npmrc in your $HOME
    2. If it has 'global = true', change to 'global = false'
    3. Now do 'npm install' in application directory. More likely, you should get all package dependent modules installed in node_modules (local) within application directory.
    0 讨论(0)
  • 2020-12-22 19:03

    I had the same error following the example on this book: "Kubernetes Up & Running".
    I see many answers suggesting to install express "by hand" but I'm not convinced is the best solution.
    Because we are using package.json (I can see it in the logs) and the right way to build the app is running npm install, I added the express dependency in the package.json file.

     "dependencies": {
        "express": "^4.17.1"
    }
    

    I get the current version with npm search express.

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

    Check if you are not install express module, use this command:

     npm install express
    

    and if your node_modules directory is in another place, set NODE_PATH envirnment variable:

     set NODE_PATH=your\directory\to\node_modules;%NODE_PATH%
    
    0 讨论(0)
  • 2020-12-22 19:11

    create one folder in your harddisk e.g sample1 and go to command prompt type :cd and gives the path of sample1 folder and then install all modules...

    npm install express

    npm install jade

    npm install socket.io

    and then whatever you are creating application save in sample1 folder

    try it...

    0 讨论(0)
  • 2020-12-22 19:12
    • sudo brew uninstall node
    • brew update
    • brew upgrade
    • brew cleanup
    • brew install node
    • sudo chown -R $(whoami) /usr/local
    • brew link --overwrite node
    • sudo brew postinstall node

    This worked for me on MacOS X Sierra

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

    In your case your express module is installed at C:\Users\Dmitry\AppData\Roaming\npm\node_modules\express, but you need to get this module in to your project directory. So you should copy the file the express module folders from C:\Users\Dmitry\AppData\Roaming\npm\node_modules\ to your project directory as : C:\ChatServer\Server\node_modules. If you do not have a folder named 'node_modules' in your project folder, then create it first and paste those files into this folder. This method worked for me on my windows pc. Restart your node server and once again run the command node C:\ChatServer\Server>node server.js. It should work now !!!!

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