All Projects β†’ hans00 β†’ fastWS

hans00 / fastWS

Licence: Apache-2.0 license
Simple Node.js server based on uWebSockets

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to fastWS

ugql
πŸš€GraphQL.js over HTTP with uWebSockets.js
Stars: ✭ 27 (+8%)
Mutual labels:  uwebsockets
m.io
An open source Moomoo.io server implementation
Stars: ✭ 20 (-20%)
Mutual labels:  uwebsockets
wsapix
Next generation Websocket framework for nodejs
Stars: ✭ 17 (-32%)
Mutual labels:  uwebsockets

fastWS

GitHub Action codecov

It's very fast Web Server Node.js server based on uWebSockets.

And very easy to use.

Benchmark result

Documents

Server package

Client package

Usage

npm i fast-ws-client fast-ws-server

Server

const fastWS = require('fast-ws-server')

const app = new fastWS({ /* options */ })

app.ws('/ws', ws => {
  console.log(`Connected ${ws.remoteAddress}`)

  ws.on('message', ({ data }) => {
    ws.sendMessage(data)
  })

  ws.on('echo', ({ reply, data }) => {
    reply(data)
  })
})

app.post('/post', async (req, res) => {
  const data = await req.body()
  res.json(data)
})

app.get('/hello/:name', async (req, res, params) => {
  res.render([
    '<html>',
    '<head><title>Hello</title></head>',
    '<body><h1>Hello, ${escapeHTML(name)}</h1></body>',
    '</html>'
  ].join(''), params)
})

app.get('/hello/:name/alert', async (req, res, params) => {
  res.render([
    '<html>',
    '<head><title>Hello</title></head>',
    '<body><script>alert("Hello, ${escapeVar(name, String)}")</script></body>',
    '</html>'
  ].join(''), params)
})

app.serve('/*') // auto serve project /static/*

app.listen(3000, () => {
  console.log('Listen on 3000')
})

Client

const Client = require('fast-ws-client')

const client = new Client('ws://server/fast-ws', options)

client.on('connect', () => {
  client.emit('event name', 'message')
})

client.on('event name', async () => {
  await client.emit('wait for remote', 'message', true)
})

Contributing

Follows conventional commits.

For example:

  • feat(Server): something for server feature.

  • fix(Client): something for client bug fix.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].