{"id":28967766,"url":"https://github.com/builtbyjonas/jsfiber","last_synced_at":"2026-04-13T18:02:08.680Z","repository":{"id":281398659,"uuid":"945002679","full_name":"builtbyjonas/jsfiber","owner":"builtbyjonas","description":"JSFiber - A JavaScript web-framework","archived":false,"fork":false,"pushed_at":"2025-04-20T15:01:03.000Z","size":92,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-15T01:14:20.473Z","etag":null,"topics":["fiber","framework","javascript","jsfiber","npm","typescript","web"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/jsfiber","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/builtbyjonas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2025-03-08T12:33:56.000Z","updated_at":"2025-04-20T15:01:07.000Z","dependencies_parsed_at":"2025-06-18T03:35:18.739Z","dependency_job_id":"9b026345-28e1-492a-961b-0e54be0b5516","html_url":"https://github.com/builtbyjonas/jsfiber","commit_stats":null,"previous_names":["binary-blazer/jsfiber","builtbyjonas/jsfiber"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/builtbyjonas/jsfiber","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtbyjonas%2Fjsfiber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtbyjonas%2Fjsfiber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtbyjonas%2Fjsfiber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtbyjonas%2Fjsfiber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/builtbyjonas","download_url":"https://codeload.github.com/builtbyjonas/jsfiber/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtbyjonas%2Fjsfiber/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31764317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T15:25:13.801Z","status":"ssl_error","status_checked_at":"2026-04-13T15:25:09.162Z","response_time":93,"last_error":"SSL_read: 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":["fiber","framework","javascript","jsfiber","npm","typescript","web"],"created_at":"2025-06-24T08:39:53.181Z","updated_at":"2026-04-13T18:02:08.674Z","avatar_url":"https://github.com/builtbyjonas.png","language":"TypeScript","readme":"# JSFiber\r\n\r\nJSFiber is a JavaScript web framework designed to be a comprehensive web server utility like Express. It provides routing, middleware, and request handling features, all while being fast and efficient.\r\n\r\n\u003e [!CAUTION]\r\n\u003e **This project is under construction** and is not fully tested and expected to be entirely working yet. Please use with caution.\r\n\r\n## Installation\r\n\r\nTo install JSFiber, use npm or the package manager of your choice.\r\n\r\n```sh\r\nnpm install jsfiber\r\n# or\r\npnpm add jsfiber\r\n# or\r\nyarn add jsfiber\r\n# or\r\nbun add jsfiber\r\n```\r\n\r\n## Usage\r\n\r\n### Starting the Server\r\n\r\nTo start the server, create a new instance of the server and call the `start` method with the desired port number:\r\n\r\n```javascript\r\nimport { Server } from \"jsfiber/server\";\r\n\r\nconst server = new Server({ infoBox: true, enableCORS: true });\r\nserver.start(3000);\r\n```\r\n\r\n### Port Availability Check\r\n\r\nThe server includes a feature to check port availability before starting. If the specified port is unavailable, the server will try subsequent ports until it finds an available one. Warnings are logged each time a new port is tried.\r\n\r\n### Defining Routes\r\n\r\nYou can define routes using the `router` instance. Here is an example of defining GET and POST routes:\r\n\r\n```javascript\r\nimport { Server } from \"jsfiber/server\";\r\nimport { Router } from \"jsfiber/router\";\r\nimport { request, response } from \"jsfiber/http\";\r\n\r\nconst server = new Server({ infoBox: true });\r\nconst router = new Router();\r\n\r\nrouter.get(\"/\", async (_req, res) =\u003e {\r\n  const resInstance = response(res);\r\n  resInstance.status(200).json({\r\n    message: 'Hello, World!',\r\n  });\r\n});\r\n\r\nrouter.post(\"/create\", async (req, res) =\u003e {\r\n  const reqInstance = request(req);\r\n  const body = await reqInstance.body;\r\n  console.log(`Body: ${body}`);\r\n\r\n  const resInstance = response(res);\r\n  resInstance.status(201).json({\r\n    message: 'Resource created',\r\n  });\r\n});\r\n```\r\n\r\n### Using Middleware\r\n\r\nYou can use the middleware router to setup middlewares to handle tasks such as logging, authentication, etc. Here is an example of using a middleware with the middleware router:\r\n\r\n```javascript\r\nimport { MiddlewareRouter } from \"jsfiber/router\";\r\n\r\nconst middleware = new MiddlewareRouter();\r\n\r\nmiddleware.use((req, res, next) =\u003e {\r\n  console.log(`${req.method} ${req.url}`);\r\n  next();\r\n});\r\n```\r\n\r\n### Additional HTTP Methods\r\n\r\nJSFiber supports additional HTTP methods such as PUT, DELETE, PATCH, HEAD, and OPTIONS. Here is an example of defining routes for these methods:\r\n\r\n```javascript\r\nrouter.put('/update', async (req, res) =\u003e {\r\n  const reqInstance = request(req);\r\n  const body = await reqInstance.body;\r\n  const resInstance = response(res);\r\n  resInstance.json({ message: 'Resource updated', received: body });\r\n});\r\n\r\nrouter.delete('/delete', (req, res) =\u003e {\r\n  const resInstance = response(res);\r\n  resInstance.json({ message: 'Resource deleted' });\r\n});\r\n\r\nrouter.patch('/modify', async (req, res) =\u003e {\r\n  const reqInstance = request(req);\r\n  const body = await reqInstance.body;\r\n  const resInstance = response(res);\r\n  resInstance.json({ message: 'Resource modified', received: body });\r\n});\r\n\r\nrouter.head('/info', (req, res) =\u003e {\r\n  const resInstance = response(res);\r\n  resInstance.text('');\r\n});\r\n\r\nrouter.options('/options', (req, res) =\u003e {\r\n  const resInstance = response(res);\r\n  resInstance.json({ message: 'OPTIONS request received' });\r\n});\r\n```\r\n\r\n### Cookie Parser\r\n\r\nJSFiber includes a built-in cookie parser. You can use it to parse cookies from the request headers. Here is an example:\r\n\r\n```javascript\r\nrouter.get(\"/cookies\", async (req, res) =\u003e {\r\n  const reqInstance = request(req);\r\n  const cookies = reqInstance.parseCookies();\r\n  console.log(`Cookies: ${JSON.stringify(cookies)}`);\r\n\r\n  const resInstance = response(res);\r\n  resInstance.status(200).json({\r\n    message: 'Cookies parsed',\r\n    cookies: cookies\r\n  });\r\n});\r\n```\r\n\r\n### CORS Support\r\n\r\nJSFiber includes built-in CORS support. You can enable CORS by including the `CorsModule` in the `modules` array in the server options. Here is an example:\r\n\r\n```javascript\r\nimport { Server } from \"jsfiber/server\";\r\n\r\nconst server = new Server({ infoBox: true, enableCORS: true });\r\nserver.start(3000);\r\n```\r\n\r\n## Full Example\r\n\r\nBellow we provide a complete full example code.\r\n\r\n```javascript\r\nimport { Server } from \"jsfiber/server\";\r\nimport { Router, MiddlewareRouter } from \"jsfiber/router\";\r\nimport { request, response } from \"jsfiber/http\";\r\n\r\nconst server = new Server({ infoBox: true, enableCORS: true });\r\nconst router = new Router();\r\nconst middleware = new MiddlewareRouter();\r\n\r\nmiddleware.use(async (req, res, next) =\u003e {\r\n  console.log(`Middleware: ${req.method} ${req.url}`);\r\n  next();\r\n});\r\n\r\nrouter.get(\"/\", async (_req, res) =\u003e {\r\n  const resInstance = response(res);\r\n  resInstance.status(200).json({\r\n    message: 'Hello, World!',\r\n  });\r\n});\r\n\r\nrouter.post(\"/create\", async (req, res) =\u003e {\r\n  const reqInstance = request(req);\r\n  const body = await reqInstance.body;\r\n  console.log(`Body: ${body}`);\r\n\r\n  const resInstance = response(res);\r\n  resInstance.status(201).json({\r\n    message: 'Resource created',\r\n  });\r\n});\r\n\r\nrouter.put(\"/update\", async (req, res) =\u003e {\r\n  const reqInstance = request(req);\r\n  const body = await reqInstance.body;\r\n  console.log(`Body: ${body}`);\r\n\r\n  const resInstance = response(res);\r\n  resInstance.status(200).json({\r\n    message: 'Resource updated',\r\n  });\r\n});\r\n\r\nrouter.delete(\"/delete\", async (_req, res) =\u003e {\r\n  const resInstance = response(res);\r\n  resInstance.status(200).json({\r\n    message: 'Resource deleted',\r\n  });\r\n});\r\n\r\nrouter.patch(\"/modify\", async (req, res) =\u003e {\r\n  const reqInstance = request(req);\r\n  const body = await reqInstance.body;\r\n  console.log(`Body: ${body}`);\r\n\r\n  const resInstance = response(res);\r\n  resInstance.status(200).json({\r\n    message: 'Resource modified',\r\n  });\r\n});\r\n\r\nrouter.head(\"/info\", async (_req, res) =\u003e {\r\n  const resInstance = response(res);\r\n  resInstance.status(200).text('');\r\n});\r\n\r\nrouter.options(\"/options\", async (_req, res) =\u003e {\r\n  const resInstance = response(res);\r\n  resInstance.status(200).json({\r\n    message: 'Options request received',\r\n  });\r\n});\r\n\r\nrouter.get(\"/cookies\", async (req, res) =\u003e {\r\n  const reqInstance = request(req);\r\n  const cookies = reqInstance.parseCookies();\r\n  console.log(`Cookies: ${JSON.stringify(cookies)}`);\r\n\r\n  const resInstance = response(res);\r\n  resInstance.status(200).json({\r\n    message: 'Cookies parsed',\r\n    cookies: cookies\r\n  });\r\n});\r\n\r\nserver.setPublicDirectory(\"public\");\r\nserver.start(3000);\r\n```\r\n\r\n## License\r\n\r\nThis project is licensed under the BSD-3-Clause License - see the [LICENSE](LICENSE) file for details.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuiltbyjonas%2Fjsfiber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuiltbyjonas%2Fjsfiber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuiltbyjonas%2Fjsfiber/lists"}