ScriptsJul 1, 2026·3 min read

Polka — Micro Web Server for Node.js

Polka is a fast, minimal Node.js web server that provides Express-compatible routing in a package under 5 KB, making it suitable for microservices and lightweight HTTP handlers.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
Polka Web Server
Direct install command
npx -y tokrepo@latest install 2fbab3e6-7569-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

Introduction

Polka is a micro web server for Node.js that delivers Express-like routing in a tiny footprint. It uses a Trouter-based path matcher for fast route resolution and maintains API compatibility with Express middleware, so existing middleware like cors, helmet, and body-parser work out of the box.

What Polka Does

  • Routes HTTP requests with Express-compatible method handlers (get, post, put, delete)
  • Resolves routes using Trouter, a lightweight trie-based path matcher
  • Supports middleware via .use() with the same (req, res, next) signature as Express
  • Handles parameterized routes and wildcard patterns
  • Returns a native http.Server, allowing direct access to Node.js server methods

Architecture Overview

Polka wraps Node.js's built-in http.createServer with a thin routing layer. Incoming requests are matched against a trie of registered routes via the Trouter library. Matched handlers execute in sequence with middleware running first. There is no built-in body parser, template engine, or view layer — Polka provides only the router and middleware pipeline, keeping the total package size under 5 KB.

Self-Hosting & Configuration

  • Requires Node.js 12 or later
  • Install with npm install polka
  • Attach middleware with .use() before defining routes
  • Call .listen(port) to start; returns a native http.Server instance
  • Deploy behind a reverse proxy (Nginx, Caddy) for TLS and load balancing

Key Features

  • Under 5 KB total size, with no dependencies beyond Trouter
  • Express-compatible middleware signature for ecosystem compatibility
  • Trie-based routing is faster than Express's linear route matching
  • Returns a standard http.Server for direct integration with Node.js APIs
  • Supports async handlers via returned Promises or async functions

Comparison with Similar Tools

  • Express — the standard Node.js framework; Polka is 30-50x smaller with faster routing
  • Fastify — schema-based validation and plugin system; Polka is simpler and smaller
  • Koa — async-first with context objects; Polka keeps the Express req/res signature
  • Hono — multi-runtime edge framework; Polka targets Node.js specifically
  • uWebSockets.js — C++ backed for raw speed; Polka uses standard Node.js http

FAQ

Q: Can I use Express middleware with Polka? A: Yes. Polka supports the standard (req, res, next) middleware signature, so most Express middleware works without changes.

Q: Does Polka support TypeScript? A: Type definitions are available via @types/polka on npm.

Q: Is Polka suitable for production? A: Yes. Its small surface area and use of native http.Server make it production-ready when paired with a reverse proxy.

Q: How does Polka handle errors? A: Polka provides an onError handler and a onNoMatch handler for 404s. Middleware can call next(err) to trigger error handling.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets