{"id":16122,"library":"micri","title":"Micri Microservices Framework","description":"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.","status":"active","version":"4.5.1","language":"javascript","source_language":"en","source_url":"https://github.com/turist-cloud/micri","tags":["javascript","micro","micri","service","microservice","API","typescript"],"install":[{"cmd":"npm install micri","lang":"bash","label":"npm"},{"cmd":"yarn add micri","lang":"bash","label":"yarn"},{"cmd":"pnpm add micri","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"`serve` is the primary function for creating and starting a programmatic HTTP server with a Micri handler.","wrong":"const server = micri(...);","symbol":"serve","correct":"import { serve } from 'micri';"},{"note":"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.","wrong":"import * as bodyParser from 'micri/body';","symbol":"{ buffer, text, json }","correct":"import { buffer, text, json } from 'micri';"},{"note":"The `Router` object provides the `router` function and methods for defining routes. It is a named export.","wrong":"import router from 'micri/router';","symbol":"Router","correct":"import { Router } from 'micri';"},{"note":"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.","wrong":"import { router } from 'micri';","symbol":"Router.router","correct":"import { Router } from 'micri'; const myRouter = Router.router(...);"},{"note":"`on` is an object containing methods (e.g., `on.get`, `on.post`) used to define specific HTTP method routes when constructing a `router`.","symbol":"on","correct":"import { on } from 'micri';"}],"quickstart":{"code":"import { serve } from 'micri';\nimport { ServerResponse, IncomingMessage, Server } from 'http';\n\nconst sleep = (ms: number): Promise<void> => new Promise((r) => setTimeout(r, ms));\n\ninterface CustomRequest extends IncomingMessage {\n  // Micri handlers receive native Node.js http.IncomingMessage\n  // You can extend it for custom properties if needed.\n}\n\nconst handler = async (req: CustomRequest, res: ServerResponse): Promise<string> => {\n  // Simulate an asynchronous operation, e.g., database call or external API fetch\n  await sleep(500);\n  \n  // Micri handlers can return a string, Buffer, or Stream directly to send as the response body.\n  return `Hello from Micri! You accessed: ${req.url}`;\n};\n\nconst PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;\nconst server: Server = serve(handler);\n\nserver.listen(PORT, () => {\n  console.log(`Micri server listening on http://localhost:${PORT}`);\n  console.log('Try opening http://localhost:3000/hello or http://localhost:3000/world in your browser.');\n});\n","lang":"typescript","description":"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."},"warnings":[{"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.","message":"Micri 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.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Implement shared logic as utility functions or compose your handlers by wrapping them with higher-order functions to apply common behaviors.","message":"Micri 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Request 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Replace all `const { symbol } = require('micri');` statements with `import { symbol } from 'micri';` for Micri imports in your ES module files.","cause":"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`).","error":"ReferenceError: require is not defined in ES module scope"},{"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;`.","cause":"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.","error":"TypeError: res.send is not a function"},{"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);`","cause":"Invoking `buffer(req)`, `text(req)`, or `json(req)` more than once for the same incoming HTTP request stream.","error":"Error: Request body already consumed"}],"ecosystem":"npm"}