Skip to content

vienly/router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#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)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published