Node JS setup

Revision as of 17:47, 9 November 2014 by WikiFreak (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Core installation

  • Node || NodeJS ==> NodeJS server runtime
  • NPM ==> NodeJS libraries manager

Automatic installation

sudo apt-get install nodejs nodejs-legacy npm

Check versions

nodejs --version
npm --version

Manual installation

The package version is usually quite "late" compare to the current one. I recommand you to use the manual installation. It's also easier to manage version evolutions ; as 'apt-get upgrade' might mess up your current settings.

Download NodeJS

Go to and get the latest binary version for your system.

Extract it into a dedicated folder and create symlinks

tar xzvf node-v0.10.33-linux-x64.tar.gz
rm node-v0.10.33-linux-x64.tar.gz
mv node-v0.10.33-linux-x64/ nodeJs-v0.10.33
ln -s /home/guillaume/Dev/nodeJs-v0.10.33 /home/guillaume/Dev/nodeJs
sudo ln -s /home/guillaume/Dev/nodeJs/bin/node /usr/bin/node
sudo ln -s /home/guillaume/Dev/nodeJs/bin/npm /usr/bin/npm

Check versions

node --version
npm --version


You can browse the available NPM libraries on [~ equivalent of]


Official website:

Bower is used to managed project's dependencies ~ like Maven on the Java world.


sudo npm install -g bower


Go to the root of your project and simply execute:

bower install

Project configuration

You need to create a bower.json at the root of your project. Set your projects settings & dependencies in that file.

You can find the list of available packages:

Example - source code from official AngularJS tutorial:

  "name": "angular-phonecat",
  "description": "A starter project for AngularJS",
  "version": "0.0.0",
  "homepage": "",
  "license": "MIT",
  "private": true,
  "dependencies": {
    "angular": "1.3.x",
    "angular-mocks": "1.3.x",
    "jquery": "1.10.2",
    "bootstrap": "~3.1.1",
    "angular-route": "1.3.x",
    "angular-resource": "1.3.x",
    "angular-animate": "1.3.x"

HTTP server

Official website:

http-server is a lightweight server.


npm install -g http-server


Go to the root of your project, then run:

http-server -p 8000 -c-1

Now you can go to http://localhost:8000 ; you should see your project.

Key options:

  • -p Port to use (defaults to 8080)
  • -a Address to use (defaults to
  • -c Set cache time (in seconds) for cache-control max-age header, e.g. -c10 for 10 seconds. To disable caching, use -c-1.


Jasmine is a test framework. That's the one used by the official AngularJS team && some related libraries. You should get familiar with that framework if you plan to use AngularJS.


npm install -g jasmine


To run your test suite, type from the root of your project:


[!] Note: If you work with AngularJS then you should run KARMA instead of Jasmine. Karma will use Jasmine for you.


Karma is a tool to run your tests inside some real browsers and devices (phones, tab, ...).


npm install -g karma

# firefox module
npm install -g karma-firefox-launcher

# Google chrome module
npm install -g karma-chrome-launcher

# Link to the Jamsine Unit test framework
npm install -g karma-jasmine

By default Karma register itself into:

  • Your current project as a "node-modules" directory
  • Common NodeJs modules into /usr/lib/node_modules/

NPM does not create a standard symlink in /usr/bin/! That's because you can use different version of Karma, depending on your projects.

You can create a link manually:

sudo ln -s /usr/lib/node_modules/karma/bin/karma /usr/bin/karma

Project configuration

karma init karma.conf.js

Answer the following questions:

  • Which testing framework do you want to use ? > jasmine
  • Do you want to use Require.js ? > no
  • Do you want to capture a browser automatically ? > Chrome > Firefox
  • What is the location of your source and test files ? > test/unit/**/*.js
  • Should any of the files included by the previous patterns be excluded ? >
  • Do you want Karma to watch all the files and run the tests on change ? > yes

Config file generated at "[...]/karma.conf.js".

You need to adjust the configuration to set the basePath and other parameters.

vim karma.conf.js

Since your configuration is in myProjet/test/ you should set a relative path:

    basePath : '../',


Go to your project's test folder and run:

karma start karma.conf.js


Karma provides advanced feature for AngularJS. You can use the following methods:



Yeoman creates skeleton for you. That's very useful! Check-out the official website:


npm install -g yo