uws-common
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

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))   // { q: 1, q: 2 }
    console.log('Text body:', await getBodyText(res))  // "Text in Request Body"
    console.log('JSON body:', await getBodyJson(res))  // { prop1: 1, prop2: 2 }
    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.

Readme

Keywords

none

Package Sidebar

Install

npm i uws-common

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

4.28 kB

Total Files

5

Last publish

Collaborators

  • rtritto