1.0.2 • Published 8 years ago

maddiekev-router v1.0.2

Weekly downloads
3
License
ISC
Repository
-
Last release
8 years ago

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 object

  • res.send is a simple method that combines res.write() and res.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 into http.createServer() in place of (req,res) so whenever a request is made, it will search through the routes 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