Fork me on GitHub

Step 1: Install

From Node Package Manager:

npm install node-simple-router

From source:

git clone https://github.com/sandy98/node-simple-router

Step 2: Test

cd to your installation directory and run npm test
then point your browser to http://localhost:8000 and review the info
and above all, try the examples.

Step 3: Run your server

You can roll your own, or use the sample server that NSR provides by means of the mk-server utility:
mk-server js will provide a barebones server (server.js) with some example routes ready to run.
In order for this to work, you must have installed NSR global, like so:
sudo npm install -g node-simple-router, or have the .bin directory of NSR in your path by whatever means you see fit.
Either case, the basic steps are the same:

Import 'http'

var http = require('http');

Import NSR

var Router = require('node-simple-router');

Instantiate the router

var router = Router(); // may also be router = new Router();

Add some routes

router.get("/hello", function(request, response) {response.end("Hello, World!"};});

Create an http server using router as the handler

var server = http.createServer(router);

Finally, make it listen on your chosen port and you're in business

server.listen(1234);


Read more...