npm.io
1.3.1 • Published 10 years ago

vien-simple-router

Licence
ISC
Version
1.3.1
Deps
0
Vulns
0
Weekly
0

#My Simple Router (as an exercise, don't actually use it)

Install the npm package from terminal

npm i --S vien-simple-router

Require in the http module

const http = require('http')
Require the router module
const Router = require('vien-simple-router')
Construct a new Router object with a root path
let router = new Router('/api');
Define the routes
router.get('/hello', (req, res) => {
  res.writeHead(200, {
    'Content-Type': 'application/json'
  });
  res.write('{"msg": "hello world"}');
  res.end();
});
Start and tell the server to listen to a specific port
http.createServer(router.route()).listen(port)