You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<i>Tweaked for high throughput, low overhead, and maximum flexibility.</i>
16
+
</div>
17
+
<br/>
18
+
19
+
## Why 0http?
20
+
21
+
- 🚀 **Blazing Fast**: One of the fastest Node.js web frameworks. Optimized for speed with smart caching and efficient routing.
22
+
- 🛠 **Highly Configurable**: Swap routers, servers, and customize behavior to fit your needs.
23
+
- 🔌 **Middleware Support**: Express-like middleware chain with full `async/await` support.
24
+
- ʦ **TypeScript Ready**: First-class TypeScript support for type-safe development.
25
+
- 🧩 **Nested Routing**: Powerful nested router support for modular architectures, optimized for static paths.
26
+
- 🛡️ **Production Ready**: Secure defaults with environment-aware error handling.
27
+
28
+
---
29
+
30
+
## Installation
9
31
10
-
Zero friction HTTP framework:
11
-
- Tweaked Node.js HTTP server for high throughput.
12
-
- High-performance and customizable request routers.
32
+
```bash
33
+
npm install 0http
34
+
```
13
35
14
-

15
-
> Check it yourself: https://web-frameworks-benchmark.netlify.app/result?f=feathersjs,0http,koa,fastify,nestjs-express,express,sails,nestjs-fastify,restana
This a `0http` extended implementation of the [trouter](https://www.npmjs.com/package/trouter) router. Includes support for middlewares, nested routers and shortcuts for routes registration.
64
-
As this is an iterative regular expression matching router, it tends to be slower than `find-my-way` when the number of registered routes increases; to mitigate this issue, we use
65
-
an internal(optional) LRU cache to store the matching results of the previous requests, resulting on a super-fast matching process.
-**defaultRoute**: Route handler when there is no router matching. Default value:
94
-
```js
95
-
(req, res) => {
96
-
res.statusCode=404
97
-
res.end()
98
-
}
99
-
```
100
-
-**cacheSize**: The size of the LRU cache for router matching. If the value is `0`, the cache will be disabled. If the value is `<0`, the cache will have an unlimited size. If the value is `>0`, an LRU Cache will be used. Default value: `-1`, for extreme performance.
101
-
-**errorHandler**: Global error handler function. Default value:
102
-
103
-
```js
104
-
(err, req, res) => {
105
-
res.statusCode=500
106
-
res.end(err.message)
107
-
}
108
-
```
109
-
110
-
***prioRequestsProcessing**: `true` to use SetImmediate to prioritize router lookup, `false` to disable. By default `true`, if used with native Node.js `http` and `https` servers. Set to `false`, if using Node.js Native Addon server, such as uWebSockets.js, as this will cause a huge performance penalty
`0http` is just a wrapper for the servers and routers implementations you provide.
168
+
### 4. Custom Servers
169
+
`0http` is server-agnostic. You can use the standard Node.js `http.Server`, `https.Server`, or even custom implementations.
170
+
175
171
```js
172
+
consthttps=require('https')
173
+
constfs=require('fs')
176
174
constzero=require('0http')
177
175
176
+
constoptions= {
177
+
key:fs.readFileSync('key.pem'),
178
+
cert:fs.readFileSync('cert.pem')
179
+
}
180
+
178
181
const { router, server } =zero({
179
-
server:yourCustomServerInstance
182
+
server:https.createServer(options)
180
183
})
184
+
185
+
server.listen(443)
181
186
```
182
187
183
-
## Node.js http.Server
184
-
If no server is provided by configuration, the standard Node.js [http.Server](https://nodejs.org/api/http.html#http_class_http_server) implementation is used.
185
-
Because this server offers the best balance between Node.js ecosystem compatibility and performance, we highly recommend it for most use cases.
|`server`| Custom server instance. |`http.createServer()`|
198
+
|`defaultRoute`| Handler for 404 Not Found. |`(req, res) => { res.statusCode = 404; res.end() }`|
199
+
|`errorHandler`| Global error handler. | Production-safe error handler (hides stack traces in prod). |
200
+
|`prioRequestsProcessing`| Use `setImmediate` to prioritize request processing. |`true` (for Node.js http/https) |
201
+
202
+
### Sequential Router Options
203
+
| Option | Description | Default |
204
+
|--------|-------------|---------|
205
+
|`cacheSize`| LRU cache size. `0` to disable, `<0` for unlimited. |`-1` (Unlimited) |
206
+
207
+
---
208
+
209
+
## Benchmarks
210
+
211
+

212
+
213
+
> **Note**: Benchmarks are subject to hardware and environment.
214
+
> Check the latest independent results: [Web Frameworks Benchmark](https://web-frameworks-benchmark.netlify.app/result?f=feathersjs,0http,koa,fastify,nestjs-express,express,sails,nestjs-fastify,restana)
215
+
216
+
**Snapshot (MacBook Pro i9, Node v12):**
217
+
-**0http (sequential)**: ~88k req/sec
218
+
-**0http (find-my-way)**: ~87k req/sec
219
+
-**restana**: ~73k req/sec
220
+
221
+
---
222
+
223
+
## Ecosystem
224
+
225
+
-**[low-http-server](https://github.com/jkyberneees/low-http-server)**: A low-level HTTP server implementation for extreme performance, originally part of 0http.
226
+
227
+
## Support
228
+
229
+
If you love this project, consider supporting its maintenance:
0 commit comments