I try to install express package using npm from inside /home/iwan/my-project directory:
npm install express
express@3.3.7 ../node_modules/express
├── method
I believe the best way to install packages with npm is to make a package.json file. Like this, just put it in the smae directory as your app. A sample package.json file could look like this:
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.3.5",
"jade": "*",
"less-middleware": "*",
"ejs": "*",
"mongoose": "3.6.*"
}
}
Take a look at the dependencies list. Just add the module that you want, for example, underscore. Just add it to the dependencies dict. Like so:
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.3.5",
"jade": "*",
"less-middleware": "*",
"ejs": "*",
"mongoose": "3.6.*",
"underscore": "*" <-------------- Added
}
}
Then head over to your directory and just run npm install, and bam! All the packages and their dependencies will be installed for you. It will do all the work, and that means making your node_modules folder for you. This is how my app directory looks like:
