Registry / web-framework / micri
library4.5.1jsnpmunverified

Micri is a lightweight, asynchronous HTTP microservices library for Node.js, currently at version 4.5.1. It provides a minimal yet high-performance foundation for building single-purpose HTTP functions, emphasizing explicit control over request handling. Key differentiators include its small codebase (~500 lines), opt-in JSON parsing for speed, and strong integration with `async`/`await` patterns for easy asynchronous operations. Unlike larger frameworks, Micri deliberately avoids middleware, requiring developers to explicitly declare and handle all dependencies within their request handlers. Its standard HTTP approach and agility make it suitable for containerized and serverless deployments. The project has a stable release cadence, with recent major updates addressing Node.js compatibility and core feature enhancements.

npm install micri
INSTALL
IMPORT
SIG · MICRI
M
micri
web-frameworkjavascriptv4.5.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

serve
import { serve } from 'micri';
const server = micri(...);
`serve` is the primary function for creating and starting a programmatic HTTP server with a Micri handler.
{ buffer, text, json }
import { buffer, text, json } from 'micri';
import * as bodyParser from 'micri/body';
These utilities are for explicitly parsing incoming request bodies (binary, plain text, or JSON). Micri does not perform automatic body parsing, requiring manual calls to these functions.
Router
import { Router } from 'micri';
import router from 'micri/router';
The `Router` object provides the `router` function and methods for defining routes. It is a named export.
Router.router
import { Router } from 'micri'; const myRouter = Router.router(...);
import { router } from 'micri';
The `router` function is a static method of the `Router` object used to create a router instance. For CommonJS, `const { Router: { router } } = require('micri');` is the common nested destructuring pattern.
on
import { on } from 'micri';
`on` is an object containing methods (e.g., `on.get`, `on.post`) used to define specific HTTP method routes when constructing a `router`.

This quickstart demonstrates creating a basic Micri HTTP server using the `serve` function, handling an asynchronous request, and listening on a specified port. It highlights Micri's `async`/`await` focus for simple handlers.

import { serve } from 'micri'; import { ServerResponse, IncomingMessage, Server } from 'http'; const sleep = (ms: number): Promise<void> => new Promise((r) => setTimeout(r, ms)); interface CustomRequest extends IncomingMessage { // Micri handlers receive native Node.js http.IncomingMessage // You can extend it for custom properties if needed. } const handler = async (req: CustomRequest, res: ServerResponse): Promise<string> => { // Simulate an asynchronous operation, e.g., database call or external API fetch await sleep(500); // Micri handlers can return a string, Buffer, or Stream directly to send as the response body. return `Hello from Micri! You accessed: ${req.url}`; }; const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000; const server: Server = serve(handler); server.listen(PORT, () => { console.log(`Micri server listening on http://localhost:${PORT}`); console.log('Try opening http://localhost:3000/hello or http://localhost:3000/world in your browser.'); });
Debug
Known issues
breakingMicri v4.0.0 dropped support for Node.js 10.x. All projects using Micri v4 and above must run on Node.js 12.0.0 or a newer compatible version.
fix
Upgrade your Node.js environment to version 12.0.0 or later. Using an active LTS version (e.g., Node.js 18 or 20) is recommended.
affects: >=4.0.0
gotchaMicri is intentionally designed without a middleware system, contrasting with frameworks like Express. All request-specific logic (e.g., authentication, logging, explicit body parsing) must be handled within your core handler functions or by wrapping them.
fix
Implement shared logic as utility functions or compose your handlers by wrapping them with higher-order functions to apply common behaviors.
affects: >=1.0.0
gotchaRequest body parsing (for JSON, URL-encoded forms, text, or binary buffers) is not automatic. Developers must explicitly call `buffer(req)`, `text(req)`, or `json(req)` to consume the incoming request body.
fix
Always use the provided `buffer`, `text`, or `json` utility functions and await their results to parse the request body. Ensure you call these functions only once per request to avoid errors.
affects: >=1.0.0
gotchaWhen using Micri's built-in router, the order of routes provided as arguments to the `router()` function determines their priority. The first matching route in the list will handle the request.
fix
Arrange your routes from the most specific to the least specific. Consider using `on.otherwise()` as the final route to gracefully handle any requests that do not match preceding rules.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
Attempting to use CommonJS `require()` syntax within an ES module context (e.g., in a file with `.mjs` extension or when `"type": "module"` is set in `package.json`).
fix
Replace all `const { symbol } = require('micri');` statements with `import { symbol } from 'micri';` for Micri imports in your ES module files.
TypeError: res.send is not a function
Attempting to use convenience methods like `res.send()` or `res.json()` that are common in frameworks like Express, but are not part of Micri's native `http.ServerResponse` object.
fix
Micri handlers operate directly with native Node.js `http.ServerResponse`. To send data, either return a string, Buffer, or Stream from your handler, or use `res.end()` for direct manipulation. For example, `return 'Hello World';` or `res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify({ message: 'Hello' })); return;`.
Error: Request body already consumed
Invoking `buffer(req)`, `text(req)`, or `json(req)` more than once for the same incoming HTTP request stream.
fix
Call body parsing functions only once per request. Store the result in a variable and reuse it throughout your handler to access the parsed body data. For example, `const requestBody = await json(req);`
Upgrade
Version history
4.5.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
micri — npm install micri · libregistry