2.0.1 • Published 11 months ago

small-router v2.0.1

Weekly downloads
10
License
ISC
Repository
github
Last release
11 months ago

node-small-router

Small router module for nodejs that allow allows users to execute callback code on a named route with or without parameters and query strings.

Dropped support for versions of node under 8.0 due to security issues with dependencies spotted by npm audit

npm version Build Status

Installation

npm install small-router

Quick Example

var http = require('http');
var router = require('small-router')(http);

router.addRoute('/', function(req, res, url) { // Standard route
  res.writeHead(200, { 'Content-Type': 'text/html' });
  res.end("Test Response");
});

router.addRoute('/test/:param([a-z]+)', function(req, res, url) { // Route with url parameter
  var param = req.parameters.param;

  res.writeHead(200, { 'Content-Text': 'text/html' });
  res.end('Parameter value: ' + param);
});

router.get('/test/get/method', function(req, res, url) { // Route that only accepts get requests

    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.end('Test get method only');
});

router.post('/test/get/method', function(req, res, url) { // Route that only accepts post requests

    res.writeHead(200, { 'Content-Type': 'text/html' });
    res;.end('Test post method only');
});

router.put('/test/put/method', function(req, res, url) { // Route that only accepts put requests

    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.end('Test put method only');
});

router.delete('/test/delete/method', function(req, res, url) { // Route that only accepts delete requests

    res.writeHead(200, { 'Content-Type': 'text/html' });
    res.end('Test delete method only');
});

router.listen(3000, function() { // Set port for router/server to listen to
  console.log("Server listening on port 3000");
});
2.0.1

11 months ago

2.0.0

11 months ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.9

4 years ago

1.1.10

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

5 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago