Prepare your NodeJS Project Using Forever, Nodeunit and ExpressJS
Overview
Prior to creating Jenkins jobs and Capistrano recipes you should prepare Node.js dependencies and scripts. This article does not provide in-depth details about Node.js.
The assumptions are that nodeunit is used for unit testing, forever for process management, and ExpressJS for creating a web server.
Step 1: Create a package.json File
Node.js dependencies and utility scripts can be configured through the package.json file. Below is an example of such a file:
{
"config": {
"unsafe-perm": true
},
"scripts": {
"test": "node_modules/.bin/nodeunit tests.js",
"start": "./node_modules/forever/bin/foreverd start app.js",
"stop": "./node_modules/forever/bin/foreverd stop app.js"
},
"dependencies": {
"express": "*",
"forever": "*",
"nodeunit": "^0.9.0"
}
}
More details can be found here:
Step 2: Add tests.js Content
Based on https://github.com/caolan/nodeunit:
exports.testSomething = function(test){
test.expect(1);
test.ok(true, "this assertion should pass");
test.done();
};
Step 3: Add a Dummy app.js File
Based on http://expressjs.com/guide.html#intro:
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send('Hello World');
});
var server = app.listen(3000, function() {
console.log('Listening on port %d', server.address().port);
});