Skip to content

This is an example of a simple router implementation for node.js.

Notifications You must be signed in to change notification settings

PZBird/nodejs-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple Router

Only for learning! Not for production! This is an example of a simple router implementation.

Usage

  • Copy the router.js file into you project.
  • Import this file and use it. Like:
const SimpleRouter = require("./router");
const app = new SimpleRouter();
  • Define middlewares with .use. Like:
app.use((req, res, next) => {
  console.log("Hello world!");
  next();
});
  • Define routers with .get or .post. Like:
app.post('/', (req, res, next) => {
  res.end('POST /');
});

or

app.get('/', (req, res, next) => {
  res.end('GET /');
});
  • Start the server:
app.listen(port);

Example

You can find an example of usage in the index.js file

About

This is an example of a simple router implementation for node.js.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published