Setting up a Node.js development environment

February 22, 2015

I recently needed to set up a Node.js development environment from scratch, so for reference I've captured here the steps I took.

Node version manager

The easiest way I have found to install Node.js is to use nvm. This avoids outdated (or broken) packages bundled with the operating system, and allows per-user selection on demand of a desired Node.js version.

Install nvm from GitHub:

$ git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
$ source ~/.nvm/nvm.sh

Install Node.js version 0.10:

$ nvm install 0.10
$ nvm use 0.10

Configure bash to set up nvm and use Node.js version 0.10 by default:

~/.bash_aliases:

source ~/.nvm/nvm.sh
nvm use 0.10

JSHint

JSHint is a very useful static analysis tool, with vim integration via Syntastic.

Install JSHint in ~/node_modules:

$ cd ~
$ npm install jshint

Configure bash to add JSHint (and other Node.js modules) to the $PATH:

~/.bash_aliases:

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

Configure JSHint:

~/.jshintrc:

{
  "predef": [
    "ve",
    "setImmediate",
    "QUnit",
    "Map",
    "Set"
  ],

  "bitwise": true,
  "laxbreak": true,
  "curly": true,
  "eqeqeq": true,
  "immed": true,
  "latedef": true,
  "newcap": true,
  "noarg": true,
  "noempty": true,
  "nonew": true,
  "regexp": false,
  "undef": true,
  "strict": true,
  "trailing": true,
  "smarttabs": true,
  "multistr": true,
  "node": true,
  "nomen": false,
  "loopfunc": true,
  "esnext": true
}

Vim

Vim is the civilized editor to use for software development. Install it via your favorite method:

# apt-get install vim

Pathogen

Pathogen makes it easy to install (and uninstall) vim plugins.

Install Pathogen:

$ mkdir -p ~/.vim/autoload ~/.vim/bundle && \
$ curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

Configure Pathogen:

~/.vimrc:

execute pathogen#infect()
syntax on
filetype plugin indent on

Syntastic

Syntastic is a vim plugin that provides syntax highlighting and static analysis (via JSHint).

Install Syntastic via Pathogen:

$ mkdir -p ~/.vim/bundle
$ git clone https://github.com/scrooloose/syntastic.git ~/.vim/bundle/syntastic

Profit

Go forth and code.