2.5.9 • Published 2 years ago

fast-ws-server v2.5.9

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

fastWS Server

npm Node version GitHub Action

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

And very easy to use.

Benchmark result

Documents


Usage

npm i fast-ws-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')
})

Feature

  • Simple to use
  • Serve static files
  • Simple WebSocket Framework
  • Reload SSL when system signal HUP(1)
  • Graceful shutdown
  • Parse body data
  • URL params parser
  • Support for template engine
  • Response from pipe stream
  • Support cache
  • Support for Socket.io
  • Support for TypeScript
  • Sub-route likes Express.js
2.5.9

2 years ago

2.5.6

2 years ago

2.5.5

2 years ago

2.5.8

2 years ago

2.5.7

2 years ago

2.3.0

2 years ago

2.5.0

2 years ago

2.4.1

2 years ago

2.2.3

2 years ago

2.4.0

2 years ago

2.3.1

2 years ago

2.5.2

2 years ago

2.2.5

2 years ago

2.5.1

2 years ago

2.4.2

2 years ago

2.2.4

2 years ago

2.5.3

2 years ago

2.2.2

2 years ago

2.1.0-alpha.1

2 years ago

2.1.0

2 years ago

2.0.1-alpha.1

3 years ago

2.0.1-alpha.0

3 years ago