To install node.js go to http://nodejs.org/ and install the latest copy of node.js .

Note: For windows

C:\Windows\System32>npm install
Error: ENOENT, stat 'C:\Users\<Your User Account Name>\AppData\Roaming\npm'
Error: EPERM, open 'C:\Windows\System32\npm-debug.log'

If you get this error, it means that this folder C:\Users\<Your User Account Name>\AppData\Roaming\npm just plain doesn't exist and you should feel bad. Actually, just create that folder, and you will be good to go.

=====================

Using the npm Package Manager

Initializing / Starting a node.js project folder

To make life with node.js easier, you should really spend some time to understand how to use a package manager. Below is some commands you should note, especially when starting a project.

On start of a node.js project. Type npm init on the root of your project folder. .

So how do you start a node.js project folder?

On the root folder of a node.js project you should type npm init.

npm init : It will ask you a set of questions, e.g. versionm description, entry point (like main() in C, but "int.js" etc...) ,, git repot, etc.... Once you answer the question, it will show a prevew of the content of the package.json

This will generate a package configeration file that might look like:

{
  "name": "javascripting",
  "version": "1.0.0",
  "description": "",
  "main": "introduction.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Adding Packages to folder

Unlike other languages like say python. In node.js installing a package will be local only to the folder itself, it's locally scoped (like in python virtural enviroment). So installing a package in one folder, does not mean it will be present in another. This might seem annoying now, but it makes versioning easier

So with the example of the package 'exampleProj', how do you install or uninstall temporarily for a project (Temporary, in the sense that it is not recorded as a dependency in project.json)?

npm install exampleProj : This command will do a local install to a folder

npm uninstall exampleProj : This command will do a local install to a folder

You will be using these above commands for temporary development work.

Recording Package installs to project.json

So when you actually do want to record a dependency (so that it will be autoinstalled on npm install command). Then you will be using the --save switch in npm.

npm install exampleProj --save : This command will install and record the dependency to project.json

npm install exampleProj@3.2.3 --save : This command is similar to above, but is restricted to a version.

npm uninstall exampleProj --save : This command will uninstall and record the removal of the dependency to project.json

Deployment

npm install : This command will read the dependency tag for package version, and install all missing packages that is necessary to make the project work quickly. You will be using this for deployment of code to clients etc...

npm uninstall : This command will read the dependency tag for package version, and remove all installed packages that matches these dependencies.


npm outsdated : This is for keeping track of versining and if we should upgrade any of the dependenceies.