nextpressjs
v1.0.0
Published
A high-performance HTTP framework for Node.js. Zero dependencies, built on native http module.
Maintainers
Readme
Nextpress
Zero-allocation Node.js HTTP framework built on node:http. No dependencies. Express-like API. V8-optimized internals.
Nextpress | ██████████████████████████████████ 121,843 req/s
Hono | ████████████████████████████ 100,077 req/s
Koa | ███████████████████████ 83,731 req/s
Fastify | ██████████████████████ 81,491 req/s
Express 5 | ███████████████████ 69,843 req/sBenchmarked with
autocannon(100 connections, 5s, pipelining 10) on Node v24.5.0 / Apple Silicon. These numbers reflect simple JSON GET responses. Real workloads will differ.
Install
npm install nextpressjsRequires Node.js >= 18. ESM only.
Quick Start
import { createServer } from 'nextpressjs';
const app = createServer();
app.get('/', (req, res) => {
res.json({ hello: 'world' });
});
app.listen(3000);API
import { createServer, jsonParser, cors, serveStatic } from 'nextpressjs';
const app = createServer();
// Middleware
app.use(jsonParser());
app.use(cors());
// Routes
app.get('/users/:id', (req, res) => {
res.json({ id: req.params.id, query: req.query });
});
app.post('/data', (req, res) => {
res.json({ received: req.body });
});
// Route groups
app.group('/api/v1', (g) => {
g.get('/health', (req, res) => res.json({ ok: true }));
});
// Static files
app.use(serveStatic('public'));
// Error handling
app.onError((err, req, res) => {
res.status(500).json({ error: err.message });
});
app.notFound((req, res) => {
res.status(404).json({ error: 'not found' });
});
app.listen(3000);Request
| Property | Description |
| -------------- | --------------------------------------- |
| req.params | Route parameters (/user/:id) |
| req.query | Parsed query string |
| req.body | Parsed body (requires jsonParser()) |
| req.pathname | URL path without query string |
| req.header(n)| Case-insensitive header lookup |
Response
| Method | Description |
| ---------------- | ------------------------------------- |
| res.json(data) | Send JSON with correct headers |
| res.send(text) | Send plain text / HTML |
| res.status(n) | Set status code (chainable) |
Benchmarks
Run them yourself:
npm install
npm run build
npm run bench:compare # Nextpress vs Raw HTTP vs Express vs Fastify
npm run bench:suite # 8 scenarios x 6 frameworksResults (Node v24.5.0, Apple Silicon)
| Framework | req/s | Latency (avg) | vs Raw HTTP | | --------- | ----: | ------------: | ----------: | | Raw HTTP | 134,406 | 6.9 ms | 100% | | Nextpress | 121,843 | 7.7 ms | 90.7% | | Hono | 100,077 | 9.5 ms | 74.5% | | Koa | 83,731 | 11.5 ms | 62.3% | | Fastify | 81,491 | 11.8 ms | 60.6% | | Express 5 | 69,843 | 13.8 ms | 52.0% |
JSON GET / with 100 connections, pipelining 10. Full results in benchmarks/results.json.
Benchmark disclaimers: Single-route, no middleware, no I/O. These measure framework overhead only. Your application's performance depends on your workload. Always benchmark your own use case.
Why it's fast
Nextpress gets its speed from four techniques. None are magic - they're just careful engineering:
1. V8 Prototype Patching
Properties like req.params, req.query, res.json() are added to IncomingMessage.prototype and ServerResponse.prototype once at import time. Every request object shares the same hidden class from birth, keeping V8's inline caches monomorphic.
2. Zero-Allocation Hot Path
Static routes reuse frozen singleton objects for params and query. The router reuses a single result object across all lookups. No closures are created per request.
3. Hybrid Router
Static routes (no :param or *) go into a flat Map for O(1) lookup. Parameterized and wildcard routes use a radix tree. Most production traffic hits static routes.
4. Minimal Syscalls
res.json() uses a single writeHead() call instead of multiple setHeader() calls. ASCII responses skip Buffer.byteLength() entirely.
Full technical deep-dive: docs/architecture.md
Project Structure
src/
server.ts Core server, request pipeline, middleware runner
router.ts Radix tree + static Map router
request-response.ts V8 prototype patching, req/res helpers
json-parser.ts JSON body parser middleware
cors.ts CORS middleware
static.ts Static file serving
types.ts TypeScript type definitions
index.ts Public exportsLimitations
Be aware of these before adopting Nextpress:
- Early-stage project. Not yet battle-tested in production environments.
- No plugin system. Only global and route-level middleware. No Fastify-style encapsulation.
- Limited ecosystem. No third-party middleware packages yet. You'll write your own or adapt Express middleware.
- ESM only. No CommonJS support. Your project needs
"type": "module". - HTTP/1.1 only. Built on
node:http. No HTTP/2 or HTTP/3. - Prototype patching. Modifies built-in prototypes at import time. Safe (adds new properties, doesn't overwrite), but means one Nextpress instance per process.
Roadmap
- [ ] Streaming response API (
res.stream()) - [ ] Lightweight plugin system
- [ ] Request validation middleware (schema-based, no deps)
- [ ] HTTP/2 support via
node:http2 - [ ] WebSocket integration
- [ ] Built-in cluster mode
- [ ] Real-world benchmark scenarios (DB queries, file I/O, auth chains)
- [ ] Better TypeScript generics for typed route params
Contributing
See CONTRIBUTING.md for setup instructions, coding guidelines, and the PR process.
Key rule: don't allocate in the hot path. Run benchmarks before and after any change to server.ts, router.ts, or request-response.ts.
