GithubHelp home page GithubHelp logo

journeyman's Introduction

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

journeyman's People

Contributors

bthesorceror avatar jonallured avatar

Watchers

Navid Nikpour avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.