maddiekev-router
v1.0.2
Published
Homework for Router Framework
Downloads
9
Readme
maddiekev-router
Homework for Router Framework
var http = require('http')
var Router = require('maddiekev-router')
var router = new Router()
router.get('/', function (req, res) {
res.send('Hello World')
})
http.createServer(router.route()).listen(3000);
Installation
$ npm install maddiekev-router
Features
- Easily creates routes for each REST request and stores its path.
- Makes routes object for easy routing access.
How to use
- Require in the router constructor from the package
var Router = require('maddiekev-router');
var router = new Router();
Specify what REST method to what request url you want to create and store the path inside the package's
routes
objectres.send
is a simple method that combinesres.write()
andres.end()
to make logging something out easy.
router.get('/route',(req,res)=>{
// Insert whatever you want the GET request to /route to do
res.send('Hello from the GET request!')
})
output:
Hello from the GET request!
router.routes()
is passed intohttp.createServer()
in place of(req,res)
so whenever a request is made, it will search through theroutes
object for that route and callback function to run.
http.createServer(router.routes()).listen(3000);
Tests
To run the test suite, first install the devDependencies in the project file, then run npm test
:
$ npm install
$ npm test
People
- Maddie Mow
- Kevin Chuang