srvx: Universal Web Standard Server

0.11.15 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import { createServer } from 'srvx';

const server = createServer((req: Request) => {
  const url = new URL(req.url);

  if (url.pathname === '/health') {
    return new Response('OK', { status: 200, headers: { 'Content-Type': 'text/plain' } });
  }

  if (url.pathname.startsWith('/api/greet')) {
    const name = url.searchParams.get('name') || 'World';
    return new Response(`Hello, ${name}!`, { headers: { 'Content-Type': 'text/plain' } });
  }

  return new Response(`Welcome to srvx! You accessed: ${url.pathname}\nTry /api/greet?name=Alice or /health`, {
    headers: { 'Content-Type': 'text/plain' },
  });
});

const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;

server.listen(PORT, () => {
  console.log(`srvx server listening on http://localhost:${PORT}`);
  console.log('Test with:');
  console.log(`- curl http://localhost:${PORT}/`);
  console.log(`- curl http://localhost:${PORT}/health`);
  console.log(`- curl "http://localhost:${PORT}/api/greet?name=User"`);
});

view raw JSON →