🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

uws-common

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uws-common

Common functions and utilities to improve DX (Developer Experience) with [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js).

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 21 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts