uws-common
Common functions and utilities to improve DX (Developer Experience) with uWebSockets.js.
Installation
yarn add uws-common
Usage
import { App } from 'uWebSockets.js'
import { getBodyJson, getBodyText, getQuery } from 'uws-common'
const port = +(process.env.PORT || 3000)
const app = App()
app
.get(pattern, async ({ req, res }) => {
console.log('Query:', getQuery(req))
console.log('Text body:', await getBodyText(res))
console.log('JSON body:', await getBodyJson(res))
res.end('Hello World!')
})
.listen(port, (listenSocket) => {
if (listenSocket) {
console.log(`Server running at http://localhost:${port}`)
} else {
console.log(`Failed to listen to port ${port}`)
}
})
License
This project is licensed under the MIT License.