0http HTTP Router
0http is a high-performance HTTP request router and server framework for Node.js, designed for high throughput and minimal overhead. Currently stable at version 4.4.0, the project maintains an active release cadence with frequent updates focused on performance, security, and Node.js compatibility. Key differentiators include its "zero friction" philosophy, highly customizable routing, and optimized Node.js HTTP server, often benchmarked among the fastest Node.js frameworks. It ships with full TypeScript type definitions since v3.5.0 and requires Node.js v22.x or higher, ensuring it leverages the latest runtime features and performance improvements.
Common errors
-
ERR_REQUIRE_ESM
cause Attempting to use CommonJS `require()` syntax in an ES module context when Node.js is configured for ESM.fixChange `const cero = require('0http');` to `import cero from '0http';` and ensure your `package.json` has `"type": "module"` or your file uses the `.mjs` extension. -
SyntaxError: Cannot use import statement outside a module
cause Attempting to use ES module `import` syntax in a CommonJS context when Node.js is configured for CJS.fixChange `import cero from '0http';` to `const cero = require('0http');` or configure your project for ESM by adding `"type": "module"` to `package.json` or using `.mjs` file extensions. -
TypeError: cero is not a function
cause You are trying to use `cero` as a variable or object directly, but it is a factory function that needs to be called to instantiate the router and server.fixEnsure `cero` is called as a function: `const { router, server } = cero();`. -
TypeError: Cannot read properties of undefined (reading 'get')
cause The `router` object was not correctly destructured or instantiated from the `cero()` factory function, or `cero()` was not called at all.fixVerify that `const { router, server } = cero();` is correctly executed and that `router` is in scope before attempting to define routes.
Warnings
- breaking Node.js v22.x or higher is now required. Older Node.js versions (below v22.x) are not supported since `0http@4.4.0` (and v20.x was required since `0http@4.2.0`).
- breaking The underlying `trouter` module was updated to v4 in `0http@4.0.0`. This may introduce breaking changes in how routes are defined, matched, or how parameters are handled.
- gotcha Versions prior to `0http@4.3.0` had potential issues with asynchronous middleware error handling, leading to unhandled exceptions or incorrect behavior.
- gotcha Enhanced error handler security was introduced in `0http@4.4.0`. Older versions might have had less robust error handling, potentially exposing sensitive information or being vulnerable to certain attacks.
Install
-
npm install 0http -
yarn add 0http -
pnpm add 0http
Imports
- cero
const cero = require('0http');import cero from '0http';
- { router, server }
import { router, server } from '0http';import cero from '0http'; const { router, server } = cero(); - Request, Response, Router, Server (types)
import { Request, Response, Router, Server } from '0http';import type { Request, Response, Router, Server } from '0http';
Quickstart
import cero from '0http';
const { router, server } = cero();
router.get('/hello', (req, res) => {
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World!');
});
router.post('/submit', (req, res) => {
let body = '';
req.on('data', chunk => { body += chunk; });
req.on('end', () => {
console.log('Received:', body);
res.statusCode = 201;
res.setHeader('Content-Type', 'text/plain');
res.end('Data received successfully!');
});
});
server.on('error', (err) => {
console.error('Server error:', err);
});
server.listen(3000, () => {
console.log('0http server listening on http://localhost:3000');
});