{"id":16121,"library":"micro","title":"Micro — Asynchronous HTTP Microservices","description":"Micro is a minimalistic library for creating ultra-lightweight, asynchronous HTTP microservices. It's built around the `async`/`await` pattern, enabling developers to write concise and highly performant request handlers with minimal boilerplate. The current stable version is 10.0.1, which introduced ES Modules support and TypeScript conversion. While it doesn't adhere to a fixed release cadence, updates are released to maintain compatibility with newer Node.js versions and modern JavaScript features. Its core differentiators include a tiny codebase (approximately 260 lines of code), explicit dependency management without implicit middleware, and a design philosophy focused on standard HTTP interactions. It is specifically intended for use within containerized environments, and the project explicitly advises against its use in serverless platforms like Vercel, where platform-native helpers often provide similar or superior functionality.","status":"active","version":"10.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/vercel/micro","tags":["javascript","micro","service","microservice","serverless","API","typescript"],"install":[{"cmd":"npm install micro","lang":"bash","label":"npm"},{"cmd":"yarn add micro","lang":"bash","label":"yarn"},{"cmd":"pnpm add micro","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Recommended for local development, providing a robust toolchain and watch mode.","package":"micro-dev","optional":true}],"imports":[{"note":"Since v10, the `micro` server factory is a default export, typically used for programmatic server setup. CommonJS `const micro = require('micro');` also works.","wrong":"import { micro } from 'micro';","symbol":"micro","correct":"import micro from 'micro';"},{"note":"One of the core utility functions for sending responses. Available as a named export since v10, and also via `micro.send` in CommonJS contexts.","wrong":"import micro, { send } from 'micro';","symbol":"send","correct":"import { send } from 'micro';"},{"note":"Utility function for parsing incoming JSON request bodies. Named export since v10; `require('micro').json` for CommonJS.","wrong":"const json = micro.json;","symbol":"json","correct":"import { json } from 'micro';"},{"note":"When using `micro` via its CLI, your entry point should export a function. ES Module default exports are preferred since v10, but CommonJS `module.exports` is still supported for compatibility.","wrong":"module.exports = async function handler(req, res) { /* ... */ };","symbol":"handler function","correct":"export default async (req: IncomingMessage, res: ServerResponse) => { /* ... */ };"}],"quickstart":{"code":"import { IncomingMessage, ServerResponse } from 'http';\nimport { json, send } from 'micro';\n\ninterface MyRequestBody {\n  name: string;\n}\n\nexport default async (req: IncomingMessage, res: ServerResponse) => {\n  if (req.method === 'POST') {\n    const data = (await json(req)) as MyRequestBody;\n    return send(res, 200, { message: `Hello, ${data.name}!` });\n  } else {\n    return 'Welcome to Micro! Send a POST request with JSON { \"name\": \"YourName\" }.';\n  }\n};\n","lang":"typescript","description":"Sets up a basic Micro service that responds to GET requests and parses JSON POST bodies."},"warnings":[{"fix":"Upgrade your Node.js environment to version 16.0.0 or higher.","message":"Version 10.0.0 drops support for Node.js versions older than 16.0.0. Projects using older Node.js runtimes will fail to start or install.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"Replace deprecated CLI arguments with `--listen <uri>`, e.g., `micro -l tcp://0.0.0.0:3000`.","message":"The command-line arguments `--port (-p)`, `--host (-h)`, and `--unix-socket (-s)` were removed in v10.0.0. Use the `--listen (-l)` option for specifying endpoint URIs.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"For serverless deployments, utilize platform-specific helpers instead of Micro. For example, on Vercel, use `req.body` and `res.send()` directly.","message":"Micro is explicitly designed for use in containerized environments and is not recommended for serverless platforms like Vercel. Vercel's built-in Serverless Function helpers often provide superior or equivalent functionality without Micro's overhead.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install `micro-dev` (`npm install --save-dev micro-dev`) and configure your `package.json` `dev` script to use it (e.g., `\"dev\": \"micro-dev\"`).","message":"For local development, it is strongly recommended to use `micro-dev` instead of `micro`. `micro-dev` provides features like file watching, automatic restarts, and better error reporting tailored for a development workflow.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your project is configured for ES Modules (e.g., `\"type\": \"module\"` in `package.json`) if using `import` statements. Review import paths and named vs. default exports.","message":"Version 10.0.0 converted `micro` to TypeScript and added ES Modules support. This might affect how you import `micro` or its helpers, especially in mixed CJS/ESM projects or older tooling.","severity":"breaking","affected_versions":">=10.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure `micro` is installed and update your `tsconfig.json` to include `node_modules/@types` or use the correct `import` statement. For CommonJS, use `require('micro')`.","cause":"Incorrect import path or missing type definitions for TypeScript.","error":"Error: Cannot find module 'micro' or its corresponding type declarations."},{"fix":"If your project is CommonJS, stick to `module.exports` for your handler. If using `import` for helpers, ensure your `package.json` has `\"type\": \"module\"` and your files use `.mjs` or are transpiled correctly.","cause":"Attempting to `require()` an ES Module in a CommonJS context, often occurring after upgrading to `micro` v10 without fully migrating to ESM.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... micro/index.js from ... not supported."},{"fix":"Either stop the conflicting process or specify a different port for Micro using `micro -l tcp://0.0.0.0:XXXX` where XXXX is an unused port.","cause":"Another process is already listening on the default Micro port (3000) or a port specified in your configuration.","error":"Error: Port 3000 is already in use."},{"fix":"Update your `start` scripts or CLI commands to use the `--listen (-l)` option, e.g., `\"start\": \"micro -l tcp://0.0.0.0:3000\"`.","cause":"Using the deprecated `--port`, `--host`, or `--unix-socket` command-line arguments from `micro` versions prior to v10.","error":"unknown option `--port`"}],"ecosystem":"npm"}