Registry / web-framework / micro
library3.1.0jsnpmunverified

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.

npm install micro
INSTALL
IMPORT
SIG · MICRO
M
micro
web-frameworkjavascriptv3.1.0
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.

micro
import micro from 'micro';
import { micro } from 'micro';
Since v10, the `micro` server factory is a default export, typically used for programmatic server setup. CommonJS `const micro = require('micro');` also works.
send
import { send } from 'micro';
import micro, { send } from 'micro';
One of the core utility functions for sending responses. Available as a named export since v10, and also via `micro.send` in CommonJS contexts.
json
import { json } from 'micro';
const json = micro.json;
Utility function for parsing incoming JSON request bodies. Named export since v10; `require('micro').json` for CommonJS.
handler function
export default async (req: IncomingMessage, res: ServerResponse) => { /* ... */ };
module.exports = async function handler(req, res) { /* ... */ };
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.

Sets up a basic Micro service that responds to GET requests and parses JSON POST bodies.

import { IncomingMessage, ServerResponse } from 'http'; import { json, send } from 'micro'; interface MyRequestBody { name: string; } export default async (req: IncomingMessage, res: ServerResponse) => { if (req.method === 'POST') { const data = (await json(req)) as MyRequestBody; return send(res, 200, { message: `Hello, ${data.name}!` }); } else { return 'Welcome to Micro! Send a POST request with JSON { "name": "YourName" }.'; } };
Debug
Known issues
breakingVersion 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.
fix
Upgrade your Node.js environment to version 16.0.0 or higher.
affects: >=10.0.0
breakingThe 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.
fix
Replace deprecated CLI arguments with `--listen <uri>`, e.g., `micro -l tcp://0.0.0.0:3000`.
affects: >=10.0.0
gotchaMicro 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.
fix
For serverless deployments, utilize platform-specific helpers instead of Micro. For example, on Vercel, use `req.body` and `res.send()` directly.
affects: >=1.0.0
gotchaFor 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.
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"`).
affects: >=1.0.0
breakingVersion 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.
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.
affects: >=10.0.0
Errors
Common errors & fixes
Error: Cannot find module 'micro' or its corresponding type declarations.
Incorrect import path or missing type definitions for TypeScript.
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')`.
Error [ERR_REQUIRE_ESM]: require() of ES Module ... micro/index.js from ... not supported.
Attempting to `require()` an ES Module in a CommonJS context, often occurring after upgrading to `micro` v10 without fully migrating to ESM.
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.
Error: Port 3000 is already in use.
Another process is already listening on the default Micro port (3000) or a port specified in your configuration.
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.
unknown option `--port`
Using the deprecated `--port`, `--host`, or `--unix-socket` command-line arguments from `micro` versions prior to v10.
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"`.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies
micro-devoptionalRecommended for local development, providing a robust toolchain and watch mode.
Agent activity
2 hits · last 30 days
node
2
Resources