Node.js

 
 
Node.js is a server-side software system designed for writing scalable Internet applications, notably web servers.
It is build on built on Chrome's JavaScript runtime. Programs are written on the server side in JavaScript, using event-driven, asynchronous I/O to minimize overhead and maximize scalability.

Node.js contains a built-in HTTP server library, making it possible to run a web server without the use of external software, such as Apache or Lighttpd, and allowing more control of how the web server works. Node.js enables web developers to create an entire web application in JavaScript, both server-side and client-side.

The latest Node.js version can be downloaded from: http://nodejs.org

Even numbered versions (0.4, 0.6, 0.8) are stable, and odd numbered versions (0.3, 0.5) are unstable. The stable releases are API-stable, which means that if you are using 0.8.1 and 0.8.2 comes out, you should be able to upgrade with no issues.







Node package manager (npm)



Information
If you install node.js, npm is included. With this tool you can install modules.

When you start your node project it first look at:
  • Its internal modules when you include a module eg: require("http"), require("fs")
  • If the module is not found, it looks in the global node_modules directory
  • If the module is not found, it looks in the local node_modules directory
  • If the module is found the package.json file is read.
    This file shows which nnn.js to read, for example "main":"underscore.js"
Operating system used
Windows Vista Home Premium SP 2

Software prerequisites
Node.js 0.10.11



Examples:
Description Command
To learn more about a certain npm command npm help <command>

Example:

npm help publish
Install module locally in a node_modules directory. If the node_modules directory does not exist, it will be created. npm install <module>

Example:

npm install underscore

Note:
If your project contains a package.json file, you install the project by using command:

npm install

Modules can also be installed globally.

In Windows Vista it is installed in directory:
C:\Users\<your_account>\AppData\Roaming\npm
npm install <module> -g

Example:

npm install underscore -g
Update modules To update a module in your project "node_modules" folder to its latest version, type:
npm update <module>

Example:

npm update underscore

To update all modules in your project "node_modules" folder to its latest versions, type:
npm update

To update all global modules to its latest versions, type:
npm update -g

npm has a registry of all the modules you can install. You can display the complete list or search for a particular word.

A complete list of all node.js modules created on June 24, 2013

You can also use: https://www.npmjs.org/
Display complete list:
npm search

Search for a particular word in the registry name, description, author or keywords:
npm search <word>

Example:

npm search iban
To view the content of a package.json file of a module npm view <module>

Example:

npm view express
Show npm version npm -v
To uninstall a module from the local node_modules directory npm uninstall <module>

Example:

npm uninstall express
To uninstall a module from the global node_modules directory npm uninstall <module> -g

Example:

npm uninstall express -g
Uninstall a module or modules from the local node_modules directory when a module or modules is/are removed from the dependencies list in the package.json file.

Example:

According to this package.json file, two local modules (node-markdown and twitter) will be installed in the node_modules folder, when the command npm install is executed in the project folder.

If you remove the twitter module from dependencies list in the package.json file, this module will be removed from the node_modules folder, when the command npm prune is executed in the project folder.

npm purge
To publish a package to the npm registry

Note:
The node project directory must contain a package.json file.
The "npm publish" command must be executed in the same directory where the package.json file is located.
npm publish

To completely remove a package from the npm registry npm unpublish --force <package_name>

Example:

npm unpublish --force mypackage
Show all possible properties for the package.json file npm help json
Show all user installed packages npm list -g --depth=0