/web

an extremely lightweight node web application framework

Primary LanguageJavaScript

web

Build Status

an extremely lightweight node web application framework

const web = require('web');
const webApp = web.server();

webApp.get('/', (req, res) => {
  res.end('Hello World');
});

webApp.listen(3000);

Table of Contents

  1. Installation
  2. Features
  3. Benchmarks
  4. Requirements

Installation

Installation is done using the npm install command:

$ npm install andydam/web

Features

  1. Router
  2. Static Files
  3. Route Params
  4. POST Request Body
  5. Everything Else

Router

const webRouter = web.router();

webRouter.get('/', (req, res) => {
  res.end('Hello World from Router');
});

webApp.use(webRouter);

Static Files

webApp.use('/static', web.static('path/to/folder'));

Route Params

webApp.get('/some/path/:dynamic', (req, res) => {
  res.end('Dynamic end point is ' + req.params.dynamic);
});

web only has support for one param at the end of static path

POST Request Body

webApp.post('/somePoint', (req, res) => {
  res.end('POST data is ' + req.body);
});

Everything Else

That's it! web only comes with extremely limited features, extending upon node's http module. This means that the request and response objects are node's http IncomingMessage and ServerResponse objects.

Benchmarks

Using hbakhtiyor's node frameworks benchmark

Simple HTTP benchmark results (wrk) with close connection

47372.89 Requests/sec - ukoa.js
35548.17 Requests/sec - ufeathers.js
*** 31403.07 Requests/sec - web.js ***
29583.14 Requests/sec - uexpress.js
555.82 Requests/sec - restify.js
551.59 Requests/sec - rawnode.js
550.16 Requests/sec - express.js
549.61 Requests/sec - hapi.js
549.23 Requests/sec - total/total.js
548.67 Requests/sec - koa.js
548.29 Requests/sec - feathers.js
546.58 Requests/sec - micro.js
173.34 Requests/sec - uws.js

Requirements

  • Node 9.4