I use "npm install -g express" on windows console.but when I try to "node app.js", it shows me the error"can not find module express",I had set the environment variable"NODE_PATH",but nothing happen ,I need your help,Thank you!
I use "npm install -g express" on windows console.but when I try to "node app.js", it shows me the error"can not find module express",I had set the environment variable"NODE_PATH",but nothing happen ,I need your help,Thank you!
Share Improve this question asked Jan 25, 2013 at 15:58 Daniel.WooDaniel.Woo 6361 gold badge10 silver badges17 bronze badges 02 Answers
Reset to default 4Globally installed modules aren't accessible without full path. You need to install express
in your project directory or it parents. Check out documentation about module loading.
npm allows two options on how to install a module: locally and globally.
A global installation (done using npm install -g xyz
) is for providing some tooling system-wide. Related to express this provides the global express
bootstrapper that you can use to create an initial frame for your app by simply typing: express .
. If you need help on what you can do with this mand, check out its help parameter: express --help
.
In contrast, a local installation of a module provides this module for a specific app. A local installation is always made to an app's node_modules
folder. When you try to require
a module, Node.js searches the this folder for the requested module.
Hence, it is perfectly fine to have express installed multiple times: Once globally for the bootstrapper, multiple times locally (once per app).
So, to cut a long story short: To make your app run, install express locally using npm install express
and that's it :-).