Node.js

From ArchWiki
Revision as of 22:55, 3 August 2014 by Rotz (talk | contribs) (created a stub article discussing package management)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Node.js is a javascript runtime environment combined with useful libraries. It uses Google's V8 engine to execute code outside of the browser. Due to its event-driven, non-blocking I/O model, it is suitable for real-time web applications.

Installation

nodejs package is available in the official repositories .

Node Packaged Modules

npm is the official package manager for node.js which is included in nodejs package.

Managing packages with npm

Installing packages

Any package can be installed using:

$ npm install packageName

This command installs the package in the current directory under node_modules and executables under node_modules/.bin .

For a system-wide installation global switch -g can be used:

$ npm -g install packageName

By default this command installs the package under /usr/lib/node_modules/npm and requires admin priviledges to do so.

For a user-wide installation you can configure npm to use a local folder instead. This can be done in various ways:

  • Manually with the --prefix command line flag (e.g. npm -g install packageName --prefix ~/.node_modules ).
  • Using the npm_config_prefix environment variable.
  • Using a user config file ~/.npmrc .

First method is not recommended since you need to remember the location and give it as the parameter each time you do an operation.

For the second method simply add the following lines to your shell configuration file (e.g. .bash_profile ).

PATH=$PATH:~/.node_modules/bin
export npm_config_prefix=~/.node_modules

Do not forget to log out and log back in or restart your shell accordingly.

For the third method you can use the command:

$ npm config edit

You can then find the prefix option and set a desired location:

prefix=~/.node_modules

Do not forget to delete the preceeding ; on the line or it will be read as a comment. You can now add the location of your executables to your shell configuration file (e.g. .bash_profile ).

PATH=$PATH:~/.node_modules/bin

Again do not forget to log out and log back in or restart your shell accordingly.

Removing packages

To remove a package installed with the -g switch simply use:

$ npm -g uninstall packageName

Listing packages

To show a tree view of the installed packages use:

$ npm -g list

Managing packages with pacman

Some node.js packages can be found in Arch User Repository with the name nodejs-packageName .