• Stars
    star
    166
  • Rank 227,748 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

✨ The simple web framework for Node.js with zero dependencies.

pure-http

Bring the middleware and router to native http.

depfu npm bundle size codefactor build coverage status eslint: airbnb code style: prettier

cover

Installation

$ npm install --save pure-http

Usage

Basic server:

const pureHttp = require('pure-http');

const app = pureHttp();

app.get('/', (req, res) => {
  res.send('Hello world');
});

app.listen(3000);

Existing server:

const http = require('http');
const pureHttp = require('pure-http');

const server = http.createServer();

const app = pureHttp({ server });

app.listen(3000);

Secure server:

const https = require('https');
const pureHttp = require('pure-http');

const server = https.createServer({
  key: ...,
  cert: ...,
});

const app = pureHttp({ server });

app.listen(3000);

Application Options:

  • server: Allows to optionally override the HTTP server instance to be used.

    Default: undefined.

  • onError: A handler when an error is thrown (Deprecated: It has been removed from 3.0.0).

    Default: ((error, req, res) => res.send(error)).

  • onNotFound: A handler when no route definitions were matched (Deprecated: It has been removed from 3.0.0).

    Default: ((req, res) => res.send("Cannot " + req.method + " " + req.url)).

  • views: An object to configuration render function.

    Default: undefined.

    • dir: A directory for the application's views.

    • ext: The default engine extension to use when omitted.

    • engine: Registers the given template engine.

  • Router Options:

    • prefix: Allow append the path before each route.

      Default: undefined.

Router

const { Router } = require('pure-http');

const router = Router();

router.get('/', (req, res) => {
  res.send('Hello world');
});

/* ... */

const pureHttp = require('pure-http');

const app = pureHttp();

app.use('/api', router);

app.listen(3000);

API References

You can read more at API.md.

Benchmarks

Please remember that your application code is most likely the slowest part of your application! Switching from Express to pure-http will (likely) not guarantee the same performance gains.

  • Machine: Ubuntu-s-1vcpu-1gb-sgp1-01, x86-64, Ubuntu 18.04.5 LTS, Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz, 16GB RAM.
  • Node: v12.18.4
  • Run: Tue, 16 Mar 2021 16:09:01
Framework Version Requests/Sec Latency
pure-http (with cache) latest ~ 6,349 15.11ms
pure-http latest ~ 6,255 15.39ms
tinyhttp 1.2.17 ~ 4,942 19.44ms
fastify 3.14.0 ~ 3,310 29.10ms
express 4.17.1 ~ 2,188 43.87ms
  • Machine: Ubuntu-s-1vcpu-1gb-sgp1-01, x86-64, Ubuntu 18.04.5 LTS, Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz, 16GB RAM.
  • Node: v12.18.4
  • Run: Fri, 13 Nov 2020 21:07:21
Framework Version Requests/Sec Latency
pure-http (with cache) 2.x.x ~ 8,792 10.92ms
pure-http 2.x.x ~ 8,633 11.12ms
polka 0.5.2 ~ 7,364 13.03ms
express 4.17.1 ~ 3,588 26.86ms
fastify 3.8.0 ~ 2,702 35.54ms

See more: BENCHMARKS

License

The code in this project is released under the MIT License.

FOSSA Status

More Repositories

1

react-ssr-starter

🔥 ⚛️ A React boilerplate for a universal web app with a highly scalable, offline-first foundation and our focus on performance and best practices.
JavaScript
60
star
2

express-react-boilerplate

(Deprecated) 🚀🚀🚀 This is a tool that helps programmers create Express & React projects easily base on react-cool-starter.
JavaScript
43
star
3

kdux

🔥🔥🔥 Android + Kotlin + Redux = ❤️ https://www.kotlinresources.com/library/kdux/
Kotlin
7
star
4

google-ads

(Unofficial) Google Ads API Nodejs Client Library
TypeScript
7
star
5

neversleep

Project is a solution to keep your heroku app never sleep.
JavaScript
6
star
6

de-express

🔥 Decorators for express framework.
JavaScript
5
star
7

moneymoney_server

💰 💰 💰 💰 💰
JavaScript
4
star
8

S.A.P

🎶 🎶 🎶 S.A.P - Simple Audio Player 🎶 🎶 🎶
HTML
2
star
9

example-mongodb-passport

JavaScript
2
star
10

NODEJS---POSTGRES---SEQUELIZE---PASSPORT-EXAMPLE

JavaScript
2
star
11

valiant

Valiant - The Chromium browser with more features.
JavaScript
2
star
12

food_server_graphql

Simple server using graphql. https://foodserver.now.sh/graphiql
JavaScript
2
star
13

get_link_chiasenhac.vn

This project is a tool online to help get link from http://chiasenhac.vn.
JavaScript
2
star
14

chat

Chat project using Nodejs, Passport and MongoDB 💬 💬 💬
JavaScript
1
star
15

example-mongodb

JavaScript
1
star
16

fake_mpa

JavaScript
1
star
17

laravel-creator

laravel-creator is a tool to help auto create a laravel project.
1
star
18

TinyRealm

This project is a simple NoSQL client for Android is used Realm database.
Java
1
star
19

angular-2-example

1
star
20

SecureSharedPreferences

This project is a one of solutions to encrypt data using Shared Preferences.
Java
1
star