{"id":47819215,"url":"https://github.com/ajayos/node-server","last_synced_at":"2026-04-03T19:02:08.744Z","repository":{"id":184838509,"uuid":"672506975","full_name":"Ajayos/node-server","owner":"Ajayos","description":"A lightweight Express-based HTTP/HTTPS server wrapper with built-in middleware, lifecycle hooks, logging, and utility helpers.","archived":false,"fork":false,"pushed_at":"2026-01-26T17:07:29.000Z","size":1397,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-27T04:47:41.235Z","etag":null,"topics":["express","express-js","expressjs","http","http-server","node"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ajayos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":"NOTICE","maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"Ajayos"}},"created_at":"2023-07-30T10:20:04.000Z","updated_at":"2026-01-26T17:07:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"23cfc069-e89a-4ebb-9ed6-bb61d303ddcf","html_url":"https://github.com/Ajayos/node-server","commit_stats":null,"previous_names":["ajayos/server","ajayos/node-server"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Ajayos/node-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ajayos%2Fnode-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ajayos%2Fnode-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ajayos%2Fnode-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ajayos%2Fnode-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ajayos","download_url":"https://codeload.github.com/Ajayos/node-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ajayos%2Fnode-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31371647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:53:18.093Z","status":"ssl_error","status_checked_at":"2026-04-03T17:53:17.617Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["express","express-js","expressjs","http","http-server","node"],"created_at":"2026-04-03T19:02:07.652Z","updated_at":"2026-04-03T19:02:08.722Z","avatar_url":"https://github.com/Ajayos.png","language":"TypeScript","readme":"# @ajayos/server\n\n\u003e A flexible, plugin-driven Express server wrapper with first-class TypeScript support, built-in middleware, and optional HTTPS.\n\n[![npm version](https://img.shields.io/npm/v/@ajayos/server.svg)](https://www.npmjs.com/package/@ajayos/server)\n[![license](https://img.shields.io/npm/l/@ajayos/server.svg)](./LICENSE)\n\n---\n\n## ✨ Overview\n\n`@ajayos/server` is a **thin, powerful wrapper around Express** that helps you:\n\n- Start HTTP or HTTPS servers easily\n- Enable common middleware using **simple config flags**\n- Extend behavior using a **plugin system**\n- Use flexible constructors (`port`, `config`, callbacks)\n- Keep server bootstrap code clean and readable\n\nDesigned to be:\n\n- ✅ Simple by default\n- 🔌 Plugin-driven when needed\n- 🧠 TypeScript-first\n- 🚀 Production-ready\n\n---\n\n## 📦 Installation\n\n```bash\nnpm install @ajayos/server\n```\n\n---\n\n## 🚀 Quick Start\n\n```ts\nimport SERVER from \"@ajayos/server\";\n\nconst app = new SERVER(3000);\n\napp.get(\"/\", (_req, res) =\u003e {\n  res.send(\"Hello World\");\n});\n\napp.start();\n```\n\n---\n\n## 🔧 Flexible Constructors\n\nAll of the following are valid:\n\n```ts\nnew SERVER(3000);\nnew SERVER(3000, () =\u003e console.log(\"started\"));\nnew SERVER(3000, { cors: true });\n\nnew SERVER({ port: 3000 });\nnew SERVER({ port: 3000 }, () =\u003e console.log(\"started\"));\n```\n\n---\n\n## ⚙️ Server Configuration\n\n```ts\ninterface ServerConfig {\n  port?: number;\n\n  https?: {\n    key: string | Buffer;\n    cert: string | Buffer;\n  };\n\n  // Built-in middleware flags\n  cors?: boolean | object;\n  helmet?: boolean | object;\n  bodyParser?: boolean | object;\n  compression?: boolean | object;\n  morgan?: boolean | string;\n  rateLimit?: boolean | object;\n  timeout?: boolean | object;\n  static?: string;\n\n  // Plugins\n  plugins?: ServerPlugin[];\n\n  // Lifecycle hooks\n  onServerStart?: () =\u003e void;\n  onServerError?: (error: any) =\u003e void;\n}\n```\n\n---\n\n## 🔐 HTTPS Support\n\n```ts\nimport fs from \"fs\";\nimport SERVER from \"@ajayos/server\";\n\nnew SERVER({\n  port: 8443,\n  https: {\n    key: fs.readFileSync(\"./key.pem\"),\n    cert: fs.readFileSync(\"./cert.pem\"),\n  },\n}).start();\n```\n\n---\n\n## 🔌 Plugins System (3 Ways)\n\nYou can add plugins **in three different ways**.\n\n---\n\n### ✅ 1️⃣ Via Config Flags (Simplest)\n\n```ts\nnew SERVER({\n  port: 3000,\n  cors: true,\n  helmet: true,\n  bodyParser: true,\n  compression: true,\n  morgan: \"dev\",\n  static: \"public\",\n}).start();\n```\n\n\u003e Built-in flags are internally converted into plugins automatically.\n\n---\n\n### ✅ 2️⃣ Via `config.plugins[]`\n\n```ts\nimport { cors, bodyParser, static as serveStatic } from \"@ajayos/server\";\n\nnew SERVER({\n  port: 3000,\n  plugins: [cors({ origin: \"*\" }), bodyParser(), serveStatic(\"public\")],\n}).start();\n```\n\n---\n\n### ✅ 3️⃣ Via `usePlugin()` (Manual)\n\n```ts\nimport { cors } from \"@ajayos/server\";\n\nconst app = new SERVER(3000);\n\napp.usePlugin(cors({ origin: \"*\" }));\n\napp.start();\n```\n\n---\n\n## 📦 Built-in Plugins List\n\nAvailable out of the box:\n\n| Plugin          | Description                     |\n| --------------- | ------------------------------- |\n| `cors()`        | Cross-Origin Resource Sharing   |\n| `helmet()`      | Security headers                |\n| `bodyParser()`  | JSON + URL-encoded body parsing |\n| `compression()` | Gzip / Brotli compression       |\n| `morgan()`      | HTTP request logging            |\n| `rateLimit()`   | Request rate limiting           |\n| `timeout()`     | Request timeout handling        |\n| `static()`      | Static file serving             |\n| `jsonError()`   | JSON parse error handling       |\n\nAll plugins are available from:\n\n```ts\nimport { cors, helmet, bodyParser } from \"@ajayos/server\";\n```\n\n---\n\n## 🧩 Plugin Usage Examples\n\n### CORS\n\n```ts\nimport { cors } from \"@ajayos/server\";\n\ncors({ origin: \"https://example.com\" });\n```\n\nor via config:\n\n```ts\nnew SERVER({\n  cors: { origin: \"*\" },\n});\n```\n\n---\n\n### Body Parser\n\n```ts\nbodyParser({ limit: \"10mb\" });\n```\n\n---\n\n### Static Files\n\n```ts\nimport { static as serveStatic } from \"@ajayos/server\";\n\nserveStatic(\"public\");\n```\n\n---\n\n### Rate Limiting\n\n```ts\nrateLimit({\n  windowMs: 60_000,\n  max: 100,\n});\n```\n\n---\n\n### JSON Parse Error Handling\n\n```ts\njsonError({ error: \"Invalid JSON body\" });\n```\n\nor with callback:\n\n```ts\njsonError((err, req, res) =\u003e {\n  res.status(400).json({\n    message: err.message,\n    path: req.path,\n  });\n});\n```\n\n\u003e Only JSON parse errors are handled. Other errors pass through.\n\n---\n\n## 🧠 Express-Compatible Routing API\n\n```ts\napp.use(middleware);\n\napp.get(\"/users\", handler);\napp.post(\"/users\", handler);\napp.put(\"/users/:id\", handler);\napp.delete(\"/users/:id\", handler);\napp.patch(\"/users/:id\", handler);\napp.all(\"/health\", handler);\n```\n\n---\n\n## 🔔 Events \u0026 Lifecycle APIs\n\n### Server Events\n\n```ts\napp.on(\"error\", (err) =\u003e {});\napp.once(\"close\", () =\u003e {});\napp.off(\"error\", handler);\n```\n\n### Express App Events\n\n```ts\napp.onApp(\"mount\", () =\u003e {});\napp.onceApp(\"mount\", () =\u003e {});\napp.offApp(\"mount\", handler);\n```\n\n---\n\n## 🌐 Network Utilities\n\n```ts\nconst interfaces = app.getActiveNetworkInterfaces();\n```\n\nReturns active IPv4 addresses (excluding localhost).\n\n---\n\n## 🛑 Graceful Shutdown\n\n```ts\napp.close();\n```\n\n---\n\n## 🧪 TypeScript Support\n\n- Written in TypeScript\n- Ships `.d.ts` files\n- Fully typed plugin system\n- Works with ESM and CommonJS\n\n---\n\n## 📄 License\n\nApache-2.0 License — free to use, modify, and distribute.\n","funding_links":["https://github.com/sponsors/Ajayos"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajayos%2Fnode-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajayos%2Fnode-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajayos%2Fnode-server/lists"}