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
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.
For me it worked when installed express locally with --save option as follow:
$ npm install express --save
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.
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
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
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
.