22
loading...
This website collects cookies to deliver better user experience
(path, locals, callback)
signature.Criteria | tinyhttp | express v4 |
---|---|---|
Minimum supported Node.js version | 12.4.0 | 0.10.0 |
Minimum supported ECMAScript version | ES2019 | ES5 (?) |
req / res extensions |
✔️ | ✔️ |
Test coverage | 92% | 100% |
Compiled to native ESM | ✔️ | ✖️ |
TypeScript support | ✔️ | ✖️ |
Package size (core only) | 35.2 kB | 208 kB |
Built-in middleware | ✖️ | ✔️ |
req
is an object containing information about the HTTP request that raised the event. In response to req
, you use res
to send back the desired HTTP response. Both tinyhttp and express v4 support req
/res
extensionsFramework | req/s | transfer/sec | latency |
---|---|---|---|
@tinyhttp/app (w/o exts) | 24575 | 3.81 MB | 3.37 ms |
@tinyhttp/app (esm) | 22820 | 3.54 MB | 4.04 ms |
@tinyhttp/app (cjs) | 22637 | 3.51 MB | 4.08 ms |
Express 4.17.1 | 12986 | 2 MB | 7.11 ms |
req/s
is number of requests per second. Latency
refers to the delay between a user's action and a web application's response to that action, also referred to as total round-trip time.req
/res
extensions) is ~1.9 times faster than Express.js.npm i @tinyhttp/app
npm install express
import { App } from '@tinyhttp/app'
const app = new App()
const PORT = 3000
app
.get('/', (_, res) => void res.send('<h1>Hello World</h1>'))
.listen(PORT, () => console.log(`Started on http://localhost:${PORT}!`))
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello world');
});
app.listen(3000, () => console.log('listening on port 3000'));
require
, we used ESM imports. tinyhttp is designed to be used with Native ESM. Unlike Express, tinyhttp is compiled to both ESM and CommonJS module systems. Meanwhile, somehow, it’s still much smaller than Express.js.import
/export
syntax in Node.js with it. To set up a Node ESM package, put "type": "module"
in the package.json
file, like this:{
"type": "module"
}
.mjs
extension. That way, you don't need to put that "type"
field in package.json
. For more information, check out the ECMAScript Modules Node.js documentation.logger
, session
, and so on.req
and res
objects. tinyhttp fully implements Express.js APIs using methods such as res.send
, res.download
, res.redirect
, and so on.import { App } from '@tinyhttp/app'
import { once } from 'events'
const app = new App()
const PORT = 3000
app.get('/', (req, res) => {
res.send('Sent a GET!')
})
app.post('/', async (req, res) => {
// Nothing complex here, we just listen to 'data' event and return the data as a promise to a `data` variable
const data = await once(req, 'data').then(d => d.toString())
// And then we send it
res.end(`Sent some data: ${data}`)
})
app.listen(PORT, () => console.log(`Started on http://localhost:${PORT}!`))
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send("Send a GET!");
});
app.post('/', function(req, res){
res.send("hello'!\n");
});
app.listen(3000);
22