journeyman

thin wrapper for middleware with node's http server

Journeyman

thin wrapper for middleware with node's http server

var Journeyman = require('journeyman');
 
var port = 3000,
    server = new Journeyman(port);
 
server.use(function(reqres) {
  res.writeHead(200);
  res.end(res.params);
});
 
server.use(function(reqresnext) { next(); });
 
server.use(function(reqresnext) {
  res.params = 'WHERE AM I??';
  next();
});
 
server.listen();

going to http://localhost:3000 will render out a success with the contents "WHERE AM I??"

Pass the path to both the ssl key and certificate

var journeyman = new Journeyman(3001, { key: 'path/to/key', cert: 'path/to/certificate' });

Journeyman will emit events at the start and end of every request-response cycle

server.on('start', function(reqres) {
  console.log('********************************');
  console.log('Response started');
  console.log('********************************');
});
server.on('end', function(reqrestime) {
  console.log('********************************');
  console.log('Response completed in ' + time + ' seconds');
  console.log('********************************');
});

The Middleware function has access to Journeyman itself through this.

In your middleware you should handle errors by calling 'this.handleError' with request, response and an error string.

Journeyman will also emit events at the beginning and end of each middleware

server.use(function(reqresnext) {
  res.params = 'WHERE AM I??';
  next();
}, 'middleware name');

Middleware name will default to 'default' if it is not set.

server.on('startMiddleware', function(reqresname) {
  console.log('********************************');
  console.log('Middleware: ' + name + ' has started');
  console.log('********************************');
});
server.on('endMiddleware', function(reqresnametime) {
  console.log('********************************');
  console.log('Middleware: ' + name + ' completed in ' + time + ' seconds');
  console.log('********************************');
});