Polka is a minimalist, high-performance web server framework for Node.js, designed to be fast and provide an Express.js-like API with a significantly smaller footprint. While the current stable version is 0.5.2, active development is happening on the `1.0.0-next` series, which frequently releases patch and minor versions, indicating a rapid release cadence for the upcoming major version. Key differentiators include its small core, focus on raw speed, and modular design through companion packages like `@polka/compression`. It provides essential routing and middleware capabilities, making it suitable for building lightweight APIs and web services where performance is critical. The `1.0.0-next` series also introduces explicit support for ESM, TypeScript (`node16`/`nodenext`), and even Deno runtimes, broadening its applicability beyond traditional Node.js CommonJS environments.
npm install polkaVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up a basic Polka server, defining a root route and a parameterized route, and starting the server to listen for requests on port 3000.
Change `error.code = 404` to `error.status = 404` in your error handling middleware.
Manually `decodeURIComponent(req.url)` or `decodeURIComponent(req.path)` if your application logic or middleware relies on decoded values from these properties.
Ensure your Node.js version is 14.18+ or 16+ for `node:` prefix support. Be mindful of module type (CommonJS vs. ESM) when importing built-in modules within Polka applications to avoid 'module not found' errors.
Remove the `toDecode` parameter from calls to `parse` in `@polka/url`. The default behavior for `req.url`/`req.path` is now percent-encoded.
Review your `tsconfig.json` `moduleResolution` and `module` options. Consider `nodenext` or `bundler` for modern Node.js and bundler environments to leverage Polka's type declarations fully.
If using `require()`, ensure you are on `polka@1.0.0-next.28` or newer and that `node:` prefixes are not used in CommonJS modules. If using `import`, ensure your Node.js version is 14.18+ or 16+ and that `node:` prefixes are included.
Ensure that `res.end()` or `next()` is called only once per request and that no further modifications to `res` occur afterwards. Use `return next(err)` or `return res.end()` to prevent further execution in middleware or route handlers.
Verify that a `polka.get('/something', ...)` or `polka.use('/something', ...)` route is correctly defined to handle the specific incoming request path and HTTP method. Ensure middleware is correctly chained or `next()` is called to pass control.