Setting Up Node.JS on Boxen

Written by

What’s Boxen?

Boxen is an automation tool for your development machine (OS X) based on Puppet. Hand’s down it’s a really nice tool, all those fine tweaks you have for your system e.g. Dock settings, show ~/Library by default, etc are configured and pushed to your git repository for your own personal use or team sharing. Suddenly tedious tasks like setting up your system for projects become super simple. Homebrew, Ruby, NGinx, Node, etc are installed simply by running boxen and can be configured based on personal or project configuration files. There is a lot more to it but I suggest you read this post for a nice detailed overview or check out the template Boxen project.

I hit a wall when it came to managing Node.js based applications, installing packages and particularly nvm related issues.

@wfarr (one of the awesome devs behind Boxen) released an update to his puppet-nodejs module. This update seemed to move away from nvm across to nodenv. There were a couple of issues I found transitioning to the latest puppet-nodejs module and thought it may be of some use documenting the simple steps I took to getting my Boxen configured to use v0.10 of Node.js, set a global default and automate installing some node packaged modules.

Puppetfile

Add the latest puppet-nodejs using the latest tag for the version (2.1.0 at the time of writing this post):

github "nodejs", "2.1.0"

Comment out or remove nvm:

#github "nvm", "1.0.0"

site.pp

Comment out or remove nvm include:

#include nvm

The example site.pp includes specific Node.js versions using the old version format. I personally removed these and added them to my personal manifest file but you can add them to another manifest as you see fit.

Comment out or remove nodejs version includes:

# node versions
#include nodejs::0-4
#include nodejs::0-6
#include nodejs::0-8

newtriks.pp (replace newtriks with your chosen manifest file name)

Add the Node.js version include:

include nodejs::v0_10

Add your global (if a system wide manifest) modules:

  nodejs::module { 'coffee-script':
    node_version => 'v0.10'
  }
  nodejs::module { 'meteorite':
    node_version => 'v0.10'
  }

I am unsure if there is a way of adding numerous modules as an array as opposed to resorting to multiple: nodejs::module?

Update 24-04-2013

There is a suggested solution to adding multiple modules here

Add a global Node.js version:

class { 'nodejs::global':
    version => 'v0.10'
}

Command line

Navigate to your Boxen repos:

cd /opt/boxen/repo

And finally run boxen and you should see output detailing Nodejs[v0.10.0] has been created along with the modules you declared. Open a new shell window and test a command and you should be up and running.

Commit your changes to your Boxen repos and your done!

Further Links

A puppet module I wrote for Charles.

Comments