0

While trying to install express js by the command "npm install -g express" in cmd prompt in windows it shows the following error

module.js:340
    throw err;
          ^
Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (D:\chapter3\sample-app\web-server.js:1:77)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

How to fix this and run a web server?

2
  • Are you sure ? You would get this error because you are running this file D:\chapter3\sample-app\web-server.js, without isntalling express. Commented Nov 29, 2013 at 8:37
  • @user568109 yes :) . but now i fixed by reinstalling express in node Commented Nov 29, 2013 at 8:53

1 Answer 1

3

You shouldn't install express globally. cd into your project directory, then npm install express.

Global package install is meant to install command line utilities; project dependencies should be installed locally, see npm's FAQ and this blog post.

Sign up to request clarification or add additional context in comments.

1 Comment

The biggest misconception with node and npm: "A global install can be used for installing a package, which can then be required anywhere"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.