Vinyll's blog

( Python, Javascript & Web stuff… )

Clean installation and management for Node with NPM

The idea of NodeJS is to use NPM (Node Package Manager) to install everything. That will generate a node_modules folder containing all packages installed with NPM.

Manual NodeJS management

package.json, the manifest

package.json is like a + a requirements.txt in Python, or a manifest.xml file in other languages. That means it holds informations like the project name, the running version, a description, and dependencies.

The purpose of dependencies from this file is that running npm install Will install them all in a node_modules folder inside the current project.

Therefore when using git, you may consider adding /node_modules/ to your project .gitignore file and still preserve dependencies.

Open the package.json file and add dependencies manually, then run npm install

But an easier way is let NPM do it all.

Auto-generation with NPM

Intialize the project

mkdir myproject
cd myproject
npm init

npm init will prompt you with a few suggestions and build a package.json file automatically

install dependencies

npm install express --save

Will install expressJS to the node_modules folder AND thanks to the --save option will also add it to your dependencies in the package.json file.

removing a package

npm uninstall express --save

Will uninstall expressJS and clean it out of packages.json.

Extra tips

List all installed package with

npm ls

I you have tip to share, just tweet me.

By vinyll on Dec. 21, 2012