{"id":25222875,"url":"https://github.com/shgysk8zer0/http-server","last_synced_at":"2025-10-25T21:30:24.562Z","repository":{"id":275064148,"uuid":"919198277","full_name":"shgysk8zer0/http-server","owner":"shgysk8zer0","description":"A powerful but lightweight node server built using web standards","archived":false,"fork":false,"pushed_at":"2025-02-04T23:08:03.000Z","size":85,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-04T23:15:15.068Z","etag":null,"topics":["dynamic-import","http","http-server","modules","node","routing","url-pattern"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@shgysk8zer0/http-server","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shgysk8zer0.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"shgysk8zer0","liberapay":"shgysk8zer0"}},"created_at":"2025-01-19T23:50:24.000Z","updated_at":"2025-02-04T23:10:50.000Z","dependencies_parsed_at":"2025-02-04T23:15:16.423Z","dependency_job_id":null,"html_url":"https://github.com/shgysk8zer0/http-server","commit_stats":null,"previous_names":["aegisjsproject/http-server","shgysk8zer0/http-server"],"tags_count":1,"template":false,"template_full_name":"shgysk8zer0/npm-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shgysk8zer0%2Fhttp-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shgysk8zer0%2Fhttp-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shgysk8zer0%2Fhttp-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shgysk8zer0%2Fhttp-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shgysk8zer0","download_url":"https://codeload.github.com/shgysk8zer0/http-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238207661,"owners_count":19434096,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dynamic-import","http","http-server","modules","node","routing","url-pattern"],"created_at":"2025-02-10T23:59:01.589Z","updated_at":"2025-10-25T21:30:24.557Z","avatar_url":"https://github.com/shgysk8zer0.png","language":"JavaScript","readme":"# `@shgysk8zer0/http-server`\n\nA powerful but lightweight node server built using web standards\n\n[![CodeQL](https://github.com/shgysk8zer0/http-server/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/shgysk8zer0/http-server/actions/workflows/codeql-analysis.yml)\n![Node CI](https://github.com/shgysk8zer0/http-server/workflows/Node%20CI/badge.svg)\n![Lint Code Base](https://github.com/shgysk8zer0/http-server/workflows/Lint%20Code%20Base/badge.svg)\n\n[![GitHub license](https://img.shields.io/github/license/shgysk8zer0/http-server.svg)](https://github.com/@shgysk8zer0/http-server/blob/master/LICENSE)\n[![GitHub last commit](https://img.shields.io/github/last-commit/shgysk8zer0/http-server.svg)](https://github.com/@shgysk8zer0/http-server/commits/master)\n[![GitHub release](https://img.shields.io/github/release/shgysk8zer0/http-server?logo=github)](https://github.com/@shgysk8zer0/http-server/releases)\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/shgysk8zer0?logo=github)](https://github.com/sponsors/shgysk8zer0)\n\n[![npm](https://img.shields.io/npm/v/@shgysk8zer0/http-server)](https://www.npmjs.com/package/@shgysk8zer0/http-server)\n![node-current](https://img.shields.io/node/v/@shgysk8zer0/http-server)\n![npm bundle size gzipped](https://img.shields.io/bundlephobia/minzip/@shgysk8zer0/http-server)\n[![npm](https://img.shields.io/npm/dw/@shgysk8zer0/http-server?logo=npm)](https://www.npmjs.com/package/@shgysk8zer0/http-server)\n\n[![GitHub followers](https://img.shields.io/github/followers/shgysk8zer0.svg?style=social)](https://github.com/shgysk8zer0)\n![GitHub forks](https://img.shields.io/github/forks/shgysk8zer0/http-server.svg?style=social)\n![GitHub stars](https://img.shields.io/github/stars/shgysk8zer0/http-server.svg?style=social)\n[![Twitter Follow](https://img.shields.io/twitter/follow/shgysk8zer0.svg?style=social)](https://twitter.com/shgysk8zer0)\n\n[![Donate using Liberapay](https://img.shields.io/liberapay/receives/shgysk8zer0.svg?logo=liberapay)](https://liberapay.com/shgysk8zer0/donate \"Donate using Liberapay\")\n- - -\n\n- [Code of Conduct](./.github/CODE_OF_CONDUCT.md)\n- [Contributing](./.github/CONTRIBUTING.md)\n\u003c!-- - [Security Policy](./.github/SECURITY.md) --\u003e\nA lightweight, modern Node.js HTTP server built entirely around Web Standards. Created to bridge the gap between Node.js servers and native browser APIs, making server-side development feel more familiar to frontend developers.\n\n## Key Features\n- Uses native [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) and [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects for handling HTTP\n- Built-in support for [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) and timeouts\n- Dynamic imports using standard ESM [`import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import)\n- Modern URL handling with [`URLPattern`](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern) for flexible routing\n- Standards-first - if it exists in the browser, we use it in Node\n- Familiar API for frontend developers\n\nWritten in pure ESM and providing a flexible configuration system, this server brings the power and familiarity of Web APIs to your Node.js backend. Whether serving static files, creating a dev server, or building a full API, you'll work with the same standards-based interfaces you already know from frontend development.\n\n## CLI Arguments\n\n| Flag | Alias | Default | Description |\n|------|--------|---------|-------------|\n| `--hostname` | `-h` | `localhost` | The hostname to serve on |\n| `--port` | `-p` | `8000` | The port number to listen on |\n| `--path` | `-a` | `/` | The path relative to project root to use for the default URL |\n| `--static` | `-s` | `/` | Root directory for static files |\n| `--open` | `-o` | `false` | Open in default browser when server starts |\n| `--timeout` | `-t` | `undefined` | Server timeout in milliseconds |\n| `--config` | `-c` | `undefined` | Path to config file |\n| `--debugger` | `-d` | `false` | Enables logging of errors via `console.error` |\n\n## Usage Examples\n\n### Basic Static Server\n```bash\nnpx @shgysk8zer0/http-server\n```\n\n### Custom Port and Hostname\n```bash\nnpx @shgysk8zer0/http-server --port=3000 --hostname=0.0.0.0\n```\n\n### Serve Static Files from Directory\n```bash\nnpx @shgysk8zer0/http-server --static=./public\n```\n\n### Using Config File\n```bash\nnpx @shgysk8zer0/http-server --config=./http.config.js\n```\n\nExample `http.config.js`:\n```js\nconst controller = new AbortController();\n\nexport default {\n  staticRoot: '/static/',\n  routes: {\n    '/favicon.svg': '@shgysk8zer0/http-server/api/favicon.js',\n    '/tasks': '@shgysk8zer0/http-server/api/tasks.js',\n  },\n  staticPaths: ['/'],\n  port: 8000,\n  signal: controller.signal,\n  open: true,\n};\n```\n\n## Using as a Module\nThe server can be imported and configured programmatically:\n\n```js\nimport { serve } from '@shgysk8zer0/http-server';\n\nconst controller = new AbortController();\nconst config = {\n port: 3000,\n hostname: 'localhost',\n staticRoot: '/public/',\n routes: {\n   '/api/data': './routes/data.js',\n   '/api/tasks/:taskId': './routes/tasks.js',\n   '/posts/:year(20\\\\d{2})/:month(0?\\\\d|[0-2])/:day(0?[1-9]|[12]\\\\d|3[01])/:post([a-z0-9\\-]+[a-z0-9])': '/js/routes/posts.js',\n },\n open: true,\n signal: controller.signal,\n};\n\nconst { url, server, whenServerClosed } = await serve(config);\nconsole.log(`Server running at ${url}`);\n\nconst resp = await fetch(new URL('/posts/2025/01/30/hello-world', url));\nconst { title, description, content, author } = await resp.json();\n\n// Handle cleanup when done\ncontroller.abort();\nwhenServerClosed.then(() =\u003e console.log(server, 'closed'));\n```\n\n### Example route/endpoint\n\n```js\nexport default async function(req) {\n  switch(req.method) {\n    case 'GET': {\n        const url = new URL(req.url);\n        const params = url.searchParams;\n        return Response.json(Object.fromEntries(params));\n\n    }\n\n    case 'POST': {\n      const data = await req.formData();\n      // Handle request with form data\n    }\n  }\n}\n```\n\n## Request \u0026 Response Middleware\n\nThe server provides a powerful middleware system through `requestPreprocessors` and `responsePostprocessors`, offering\ndeep control over the request/response lifecycle.\n\n### Request Preprocessors\n\nRequest preprocessors run before route handling and can:\n\n- Filter/block requests\n- Modify the request object\n- Enhance the request context with additional data\n- Perform validation or authentication\n- Add logging or monitoring\n- Abort requests early\n- Skip request handling with aborting request or cached response\n- Mutate the `context` object with eg geoip data\n\nEach preprocessor receives the request object and a context object containing:\n\n- `ip` - Remote IP address\n- `url` - Complete request URL\n- `cookies` - Cookie management\n- `controller` - Request's abort controller\n- `signal` - Abort signal for the request\n\n### Response Postprocessors\n\nRun on `Response`s returned by handlers (or cache) that can:\n\n- Add headers to responses, such as CORS\n- Add responses to a cache\n- Pipe response streams through transform streams such as `CompressionStream` using `resp.body.pipeThrough()`\n\nBoth types of middleware can be provided as direct functions, importable modules, or factory functions that return\nconfigurable handlers. The system's flexibility allows you to compose complex request/response pipelines while\nmaintaining clean separation of concerns.\n","funding_links":["https://github.com/sponsors/shgysk8zer0","https://liberapay.com/shgysk8zer0","https://liberapay.com/shgysk8zer0/donate"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshgysk8zer0%2Fhttp-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshgysk8zer0%2Fhttp-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshgysk8zer0%2Fhttp-server/lists"}