NPM comes installed with Node so you don't have to add anything new.


Let's take a look at a package.json file:

{
    "name": "your-application-name",
    "version": "1.0.0",
    "engines": {
        "node": ">= 0.10.0"
    },
    "scripts": {
        "start": "node app.js"
    },
    "dependencies": {
        "express": "4.x"
    }
}

At a minimum the package.json file must contain a name and a version. The dependencies are identified with a version number following a specific syntax.


npm install

This command will read the package.json file located in the current directory and install all the packages listed in the dependencies object.


npm install some-package-name --save

Alternatively you can manually install each module. The --save option adds the module name and version number to the package.json file.


npm init

Will guide you through creating a package.json file from scratch. Or you can just copy the one above and modify from there.


npm install -g some-program-name

The -g tells npm to install the program not just in the current directory, but in the users directory so that it is universally accessible. For Mac OS users make sure to add sudo before npm as in:

sudo npm install -g some-program-name