Getting Started
Build HTTP servers with web standard APIs like fetch, Request, and Response.
Quick Start (CLI)
Create a server entry:
server.ts
export default {
fetch(req: Request) {
return Response.json({ hello: "world!" });
},
};
Then, run the server using your favorite runtime:
npx srvx
pnpx srvx
yarn dlx srvx
deno -A npm:srvx
bunx --bun srvx
You can also try examples in the online playground
Quick Start (API)
Instead of using the srvx CLI, you can directly import the serve method to define a self-listening server entry.
Create a server entry:
server.ts
import { serve } from "srvx";
const server = serve({
fetch(request) {
return Response.json({ hello: "world!" });
},
});
Install srvx as a dependency:
npm i srvx
yarn add srvx
pnpm i srvx
bun i srvx
deno i npm:srvx
Then, run the server using your favorite runtime:
node server.mjs
deno run --allow-env --allow-net server.mjs
bun run server.mjs
TypeScript
srvx ships one shared set of type definitions covering every supported runtime. The runtime types they reference come from ambient type packages, declared as optional peerDependencies so that nothing is installed unless you ask for it:
| Runtime | Types package |
|---|---|
| Node.js | @types/node |
| Deno | @types/deno |
| Bun | @types/bun |
| Cloudflare Workers | @cloudflare/workers-types |
| AWS Lambda | @types/aws-lambda |
| Service Worker | @types/serviceworker |
@types/deno references DOM types, so pair it with lib: ["esnext", "dom"].
Because the definitions are shared,
tsc with skipLibCheck: false also resolves the references of runtimes you do not target and reports the missing ones. Installing all of them is not a way out — @types/serviceworker redeclares globals (Blob, Request, GPU*, …) that @types/bun and @types/deno declare too, and TypeScript's own lib: ["webworker"] collides with @types/bun the same way — so keep skipLibCheck: true (what tsc --init generates).Starter Examples
| Example | Source | Try |
|---|---|---|
aws-lambda | examples/aws-lambda | npx giget gh:h3js/srvx/examples/aws-lambda srvx-aws-lambda |
elysia | examples/elysia | npx giget gh:h3js/srvx/examples/elysia srvx-elysia |
express | examples/express | npx giget gh:h3js/srvx/examples/express srvx-express |
fastify | examples/fastify | npx giget gh:h3js/srvx/examples/fastify srvx-fastify |
h3 | examples/h3 | npx giget gh:h3js/srvx/examples/h3 srvx-h3 |
hello-world | examples/hello-world | npx giget gh:h3js/srvx/examples/hello-world srvx-hello-world |
hono | examples/hono | npx giget gh:h3js/srvx/examples/hono srvx-hono |
jsx | examples/jsx | npx giget gh:h3js/srvx/examples/jsx srvx-jsx |
node-handler | examples/node-handler | npx giget gh:h3js/srvx/examples/node-handler srvx-node-handler |
service-worker | examples/service-worker | npx giget gh:h3js/srvx/examples/service-worker srvx-service-worker |
streaming | examples/streaming | npx giget gh:h3js/srvx/examples/streaming srvx-streaming |
tracing | examples/tracing | npx giget gh:h3js/srvx/examples/tracing srvx-tracing |
websocket | examples/websocket | npx giget gh:h3js/srvx/examples/websocket srvx-websocket |