{"id":12065,"library":"srvx","title":"srvx: Universal Web Standard Server","description":"srvx is a modern, zero-dependency HTTP server framework built on Web Standards (Request/Response API), enabling consistent deployment and execution across multiple JavaScript runtimes including Node.js, Deno, and Bun. It currently stands at version 0.11.15, with active development primarily focusing on bug fixes and performance enhancements in its frequent patch releases. A key differentiator is its emphasis on Web Standard APIs, providing a unified programming model regardless of the underlying runtime. It also boasts a full-featured Command Line Interface (CLI) that includes a file watcher, error handling, static file serving, and logging, streamlining the development workflow. srvx aims for close-to-native performance, especially in Node.js environments.","status":"active","version":"0.11.15","language":"javascript","source_language":"en","source_url":"https://github.com/h3js/srvx","tags":["javascript","typescript"],"install":[{"cmd":"npm install srvx","lang":"bash","label":"npm"},{"cmd":"yarn add srvx","lang":"bash","label":"yarn"},{"cmd":"pnpm add srvx","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"srvx is primarily an ESM-first package; CommonJS 'require' syntax will generally result in ERR_REQUIRE_ESM for named exports.","wrong":"const { createServer } = require('srvx')","symbol":"createServer","correct":"import { createServer } from 'srvx'"},{"note":"Import the `Server` type for explicit type annotations when working with programmatic server instances in TypeScript.","symbol":"Server (type)","correct":"import { Server } from 'srvx'"},{"note":"When using the `srvx` CLI to serve a file, the file should default export an object containing a `fetch` method, adhering to the Web Standard Request/Response API. No explicit `import` of `srvx` is typically needed within the handler file itself for this usage pattern.","symbol":"srvx CLI handler (default export)","correct":"// my-handler.js\nexport default {\n  fetch(req: Request) {\n    return new Response('Hello from CLI handler!');\n  },\n};"}],"quickstart":{"code":"import { createServer } from 'srvx';\n\nconst server = createServer((req: Request) => {\n  const url = new URL(req.url);\n\n  if (url.pathname === '/health') {\n    return new Response('OK', { status: 200, headers: { 'Content-Type': 'text/plain' } });\n  }\n\n  if (url.pathname.startsWith('/api/greet')) {\n    const name = url.searchParams.get('name') || 'World';\n    return new Response(`Hello, ${name}!`, { headers: { 'Content-Type': 'text/plain' } });\n  }\n\n  return new Response(`Welcome to srvx! You accessed: ${url.pathname}\\nTry /api/greet?name=Alice or /health`, {\n    headers: { 'Content-Type': 'text/plain' },\n  });\n});\n\nconst PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;\n\nserver.listen(PORT, () => {\n  console.log(`srvx server listening on http://localhost:${PORT}`);\n  console.log('Test with:');\n  console.log(`- curl http://localhost:${PORT}/`);\n  console.log(`- curl http://localhost:${PORT}/health`);\n  console.log(`- curl \"http://localhost:${PORT}/api/greet?name=User\"`);\n});","lang":"typescript","description":"This quickstart demonstrates how to programmatically create and run an srvx server that handles basic routing using Web Standard Request and Response objects. It sets up a health check endpoint and a personalized greeting API, listening on a configurable port."},"warnings":[{"fix":"Upgrade your Node.js runtime to version 20.16.0 or newer. Use a version manager like `nvm` to switch or update your Node.js environment.","message":"srvx explicitly requires Node.js version 20.16.0 or higher. Deployments on older Node.js environments will fail to start or encounter runtime errors due to reliance on newer APIs.","severity":"breaking","affected_versions":"<0.11.0"},{"fix":"Exercise caution when upgrading between minor versions. Always review the changelog for potential breaking changes. Consider pinning to exact patch versions (`0.11.15`) or using a lockfile to ensure stability in production environments.","message":"As a package in its 0.x.x version series, srvx may introduce breaking changes in minor releases (e.g., 0.11.x to 0.12.x) without adhering strictly to Semantic Versioning, which typically reserves breaking changes for major version increments.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Implement robust error handling around `getReader` and other asynchronous I/O operations within your srvx handlers to gracefully manage potential failures.","message":"Beginning with version 0.11.15, `srvx` no longer silently swallows errors originating from `getReader` operations. This means applications that previously had errors silently ignored may now experience unhandled promise rejections or exceptions.","severity":"gotcha","affected_versions":">=0.11.15"},{"fix":"Ensure all clients and proxy configurations send valid `Host` headers that conform to HTTP specifications. Debug with detailed logging to identify the source of invalid headers if issues arise.","message":"Since version 0.11.8, srvx performs validation of the `Host` header. Requests with invalid or malformed `Host` headers that might have been processed in earlier versions will now be rejected, which could affect certain proxy setups or custom client implementations.","severity":"gotcha","affected_versions":">=0.11.8"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change the server's listening port to an available one (e.g., `server.listen(3001)`), or identify and terminate the process that is already using the port.","cause":"Another process is currently bound to the specified network port (e.g., 3000), preventing srvx from starting.","error":"Error: listen EADDRINUSE: address already in use :::3000"},{"fix":"Update your import statements to use ES module syntax (e.g., `import { createServer } from 'srvx'`). Ensure your project's `package.json` specifies `\"type\": \"module\"` or use `.mjs` file extensions for ES Modules.","cause":"Attempting to import srvx using CommonJS `require()` syntax (`const srvx = require('srvx')`) in a JavaScript module environment configured for ESM.","error":"ERR_REQUIRE_ESM"},{"fix":"Install the package using your package manager (e.g., `npm install srvx`, `pnpm add srvx`, or `yarn add srvx`). If using TypeScript, ensure `tsconfig.json` is correctly configured to include `node_modules/@types`.","cause":"The 'srvx' package has not been installed, the import path is incorrect, or TypeScript cannot locate its type definition files.","error":"Cannot find module 'srvx' or its corresponding type declarations."}],"ecosystem":"npm"}