By default npm packages should install into local directory and automatically create node_modules directory in your app directory. This was not happening for me, so I worked around it by
1) manually creating package.json file and place it in my main project directory.
{ "name": "wine-cellar", "description": "Wine Cellar Application", "version": "0.0.1", "private": true, "dependencies": { "express": "3.x" } }
2) Run
</pre> npm install <pre>
The module express was installed locally in node_module folder.
3) After this try doing any project which
npm ls
This lists all the modules installed.
If you have any module installed locally which has not been mentioned in package.json you will get the beow error on trying npm ls
npm ERR! extraneous: ejs@1.0.0 /Users/nivedita/Documents/nodeapp/node_modules/ejs npm ERR! extraneous: geohash@0.0.1 /Users/nivedita/Documents/nodeapp/node_modules/geohash npm ERR! not ok code 0
Use :
npm install xxx --save
to automatically add xxx to the package.json