@prexjs/prex
v1.0.0-beta
Published
Fast, unopinionated, and modular web framework for Node.js built with modern TypeScript.
Readme
@prexjs/prex
Fast, unopinionated, and modular web framework for Node.js built with modern TypeScript.
@prexjs/prex is a lightweight, high-performance web framework for Node.js. Architected as a modular TypeScript suite, it delivers familiar Express-compatible routing and middleware mechanics with native asynchronous promise resolution, built-in body parsing, static file serving, and CORS support.
Features
- Express-Compatible API: Frictionless migration with familiar application, request, response, and router primitives.
- Async & Promise-First: Route handlers naturally await promises with automated rejection forwarding to error middleware.
- Modular Monorepo Foundation: Every component—from ETag calculation to body parsers and content negotiation—is cleanly decoupled into its own independent package.
- Built-In Essentials: Direct access to
prex.json(),prex.urlencoded(),prex.raw(),prex.text(),prex.static(), andprex.cors(). - First-Class TypeScript: Exhaustive type definitions for request parameters, response locals, middleware handlers, and application settings.
- Dual CJS & ESM Support: Ready for ES Modules (
import) and CommonJS (require).
Installation
Install using your preferred package manager:
# npm
npm install @prexjs/prex
# pnpm
pnpm add @prexjs/prex
# Yarn
yarn add @prexjs/prex
# Bun
bun add @prexjs/prexQuick start
import prex from '@prexjs/prex';
const app = prex();
// Middleware
app.use(prex.json());
app.use(prex.cors());
// Route definition
app.get('/api/users/:id', async (req, res) => {
const userId = req.params.id;
res.json({ id: userId, name: 'Alice', active: true });
});
// Static assets
app.use('/static', prex.static('public'));
// Start server
app.listen(3000, () => {
console.log('Prex server running at http://localhost:3000');
});Core Modules & Exports
| Export | Description | Package Source |
|---|---|---|
| prex() / createApplication() | Creates an application instance | @prexjs/application |
| prex.Router / Router | Modular route dispatcher | @prexjs/router |
| prex.json() | JSON request body parser | @prexjs/body-parser |
| prex.urlencoded() | URL-encoded form parser | @prexjs/body-parser |
| prex.raw() | Raw buffer body parser | @prexjs/body-parser |
| prex.text() | Text body parser | @prexjs/body-parser |
| prex.static() | Static file streaming middleware | @prexjs/serve-static |
| prex.cors() | Cross-Origin Resource Sharing | @prexjs/cors |
| prex.request | HTTP Request prototype | @prexjs/request |
| prex.response | HTTP Response prototype | @prexjs/response |
Compatibility
- Node.js >= 18.0.0
- Supports both ESM and CommonJS
- TypeScript 5.0+
Ecosystem
The @prexjs monorepo consists of 50+ focused, highly optimized utilities including:
@prexjs/rate-limit: Endpoint rate limiting.@prexjs/session: Cookie-based session management.@prexjs/http-errors: Standardized HTTP errors.@prexjs/accepts: Content negotiation.
