Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
thin wrapper for middleware with node's http server
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
features
test
.gitignore
.travis.yml
README.md
index.js
middleware.js
package.json
profiler.js

README.md

Journeyman

Build Status

NPM

NPM

thin wrapper for middleware with node's http server

Example

var Journeyman = require('journeyman');

var port = 3000,
    server = new Journeyman(port);

server.use(function(req, res) {
  res.writeHead(200);
  res.end(res.params);
});

server.use(function(req, res, next) { next(); });

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

server.listen();

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

SSL support

Pass the path to both the ssl key and certificate

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

Now with time profiling

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

The Start Event

server.on('start', function(req, res) {
  console.log('********************************');
  console.log('Response started');
  console.log('********************************');
});

The End Event

server.on('end', function(req, res, time) {
  console.log('********************************');
  console.log('Response completed in ' + time + ' seconds');
  console.log('********************************');
});

Middleware error handling

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.

Middleware time profiling

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

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

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

The startMiddleware Event

server.on('startMiddleware', function(req, res, name) {
  console.log('********************************');
  console.log('Middleware: ' + name + ' has started');
  console.log('********************************');
});

The endMiddleware Event

server.on('endMiddleware', function(req, res, name, time) {
  console.log('********************************');
  console.log('Middleware: ' + name + ' completed in ' + time + ' seconds');
  console.log('********************************');
});

Available middleware

Something went wrong with that request. Please try again.