{"id":15068286,"url":"https://github.com/spurreiter/uws-connect","last_synced_at":"2025-09-25T20:26:02.065Z","repository":{"id":36985236,"uuid":"492978763","full_name":"spurreiter/uws-connect","owner":"spurreiter","description":"Use connect like middlewares with uWebSockets.js.","archived":false,"fork":false,"pushed_at":"2025-02-24T01:28:20.000Z","size":168,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T14:11:12.708Z","etag":null,"topics":["connect","express","expressjs","fast","http-server","https-server","router","uwebsocketsjs","uws","websocket","websockets"],"latest_commit_sha":null,"homepage":"","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/spurreiter.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2022-05-16T19:49:38.000Z","updated_at":"2025-03-22T12:22:35.000Z","dependencies_parsed_at":"2025-02-11T20:37:23.255Z","dependency_job_id":null,"html_url":"https://github.com/spurreiter/uws-connect","commit_stats":{"total_commits":34,"total_committers":1,"mean_commits":34.0,"dds":0.0,"last_synced_commit":"bd2a74e4215cf2134a4ab73dfc1d86911c89d8af"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spurreiter%2Fuws-connect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spurreiter%2Fuws-connect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spurreiter%2Fuws-connect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spurreiter%2Fuws-connect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spurreiter","download_url":"https://codeload.github.com/spurreiter/uws-connect/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248252659,"owners_count":21072699,"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":["connect","express","expressjs","fast","http-server","https-server","router","uwebsocketsjs","uws","websocket","websockets"],"created_at":"2024-09-25T01:33:07.339Z","updated_at":"2025-09-25T20:26:02.057Z","avatar_url":"https://github.com/spurreiter.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# uws-connect\n\nUse connect like middlewares with [uWebSockets.js][].\n\nProvides support for\n\n- connect helper for connecting connect, express middlewares\n- body-parser (json, form-urlencoded)\n- nodejs streams support for `uWS.HttpRequest` and `uWS.HttpResponse`\n  (may not be 100% compliant with nodejs streams)\n- final handler for errors\n\nThe design aims to be as fast and unopinionated as possible.\n\nAll parts provided can also be used as single building blocks.\n\n**Table of Contents**\n\n\u003c!-- !toc (omit=\"uws-connect\") --\u003e\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [License](#license)\n- [References](#references)\n\n\u003c!-- toc! --\u003e\n\n# Installation\n\n```sh\nnpm install uws-connect\n```\n\n# Usage\n\n```js\nimport { App, bodyParser, params } from 'uws-connect'\nimport { Transform } from 'stream'\n\nconst app = App()\n\napp.use((req, res, next) =\u003e { // a simple logging mw applied to all routes\n  const { method, url } = req\n  console.log('%s %s', method, url)\n  next()\n})\napp.get('/',\n  // a connect like middleware\n  (req, res, next) =\u003e {\n    next()\n    },\n  // async middleware (no need for `next()` or `try {} catch (err) {}`)\n  async (req, res) =\u003e {\n    res.body = await something()\n  },\n  (req, res) =\u003e {\n    res.end(res.body)\n  }\n)\napp.put('/users/:user', // does req.params parsing like with express.\n  // does json or form body parsing.\n  bodyParser({ limit: 100000 }),\n  (req, res) =\u003e {\n    // restana like res.send method\n    // res.send(data: any, status?: number, headers?: object) =\u003e void\n    res.send({\n      params: req.params,\n      body: req.body,     // from `bodyParser()` middleware\n    })\n  }\n)\n\n// if stream support is needed...\nconst transform = new Transform({\n  transform (chunk, enc, cb) {\n    this.push(_chunk)\n    cb()\n  }\n})\napp.post('/echo',\n  (req, res) =\u003e { req.pipe(transform).pipe(res) }\n)\n\napp.listen(9001)\n```\n\nIf you need to better fine tune the performance of your app and don't want to\ntrade speed, use `glue(...handlers)` for connecting middlewares.\n\n```js\n// same as `import uWs from 'uWebSockets.js'`\nimport { uWS, connect, params } from 'uws-connect'\nimport cors from 'cors'\nconst uwsApp = uWS.App()\n\n// just uWS, as fast as fast can be\n// NOTE: (response, request) for uWS handler\nuwsApp.get('/', (response, request) =\u003e response.end('done'))\n\n// use some routes with connect middlewares (like cors)\n// NOTE: glue() uses express (req, res, next) handlers!\nconst _cors = cors()\nconst glue = connect()\nuwsApp.options('/*', glue(_cors))\nuwsApp.get('/with-cors/:param', glue(\n  _cors,\n  params('/with-cors/:param'), // must use the same path as the route\n  (req, res) =\u003e res.end(`with cors - ${req.params.param}`))\n)\n\nuwsApp.listen(9001, () =\u003e {})\n```\n\n# Benchmarks\n\n```\n$ cd benchmark\n$ node index.js -d 10 -c 2500 -p 4\n```\n\n\\*) Results may vary on your machine.\n\n| Package     | Version | Requests/s | Latency (ms) | Throughput (Mb) |\n| :---------- | ------: | ---------: | -----------: | --------------: |\n| uWebSockets | 20.52.0 |     365266 |        45.84 |           37.27 |\n| uws-connect |   1.4.0 |     225102 |        52.39 |           19.32 |\n| native      |  24.4.1 |     125107 |        44.20 |           16.34 |\n| polka       |   0.5.2 |     119533 |        44.85 |           15.62 |\n| restana     |   5.0.0 |     109485 |        60.59 |           14.31 |\n| express     |   5.1.0 |      87974 |        58.47 |           11.49 |\n\n\n# Contributing\n\nYour help is appreciated. File an issue and fork this project to contribute with\nyour ideas.\n\nPlease follow the minimalistic approach as chosen here. Keep things simple.\n\nIf you contribute code to this project, you are implicitly allowing your code to\nbe distributed under the MIT license. You are also implicitly verifying that all\ncode is your original work or correctly attributed with the source of its origin\nand license.\n\nThe Code-of-Conduct is [Contributor Covenant Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/).\n\n# License\n\nMIT Licensed\n\n# References\n\n\u003c!-- !ref --\u003e\n\n- [uWebSockets.js][uWebSockets.js]\n- [uWebSockets.js documentation][uWebSockets.js documentation]\n\n\u003c!-- ref! --\u003e\n\n[uWebSockets.js]: https://github.com/uNetworking/uWebSockets.js\n[uWebSockets.js documentation]: https://unetworking.github.io/uWebSockets.js/generated/index.html\n\n\u003c!--\nhttps://nodejs.org/en/docs/guides/backpressuring-in-streams/\n--\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspurreiter%2Fuws-connect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspurreiter%2Fuws-connect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspurreiter%2Fuws-connect/lists"}