Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hans00/fastws
Simple Node.js server based on uWebSockets
https://github.com/hans00/fastws
javascript nodejs uwebsockets websocket
Last synced: 17 days ago
JSON representation
Simple Node.js server based on uWebSockets
- Host: GitHub
- URL: https://github.com/hans00/fastws
- Owner: hans00
- License: apache-2.0
- Created: 2019-11-13T13:28:01.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-27T14:10:28.000Z (over 1 year ago)
- Last Synced: 2024-10-11T18:12:39.215Z (about 1 month ago)
- Topics: javascript, nodejs, uwebsockets, websocket
- Language: JavaScript
- Homepage:
- Size: 2.28 MB
- Stars: 27
- Watchers: 4
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
fastWS
=====[![GitHub Action](https://github.com/hans00/fastWS/workflows/build/badge.svg)](https://github.com/hans00/fastWS)
[![codecov](https://codecov.io/gh/hans00/fastWS/branch/master/graph/badge.svg?token=5P1YR45NCD)](https://codecov.io/gh/hans00/fastWS)It's very fast Web Server Node.js server based on uWebSockets.
And very easy to use.
[Benchmark result](benchmark/README.md)
[Documents](docs/README.md)
[Server package](packages/server)
[Client package](packages/client)
Usage
---`npm i fast-ws-client fast-ws-server`
### Server
```js
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([
'',
'Hello',
'Hello, ${escapeHTML(name)}
',
''
].join(''), params)
})app.get('/hello/:name/alert', async (req, res, params) => {
res.render([
'',
'Hello',
'alert("Hello, ${escapeVar(name, String)}")',
''
].join(''), params)
})app.serve('/*') // auto serve project /static/*
app.listen(3000, () => {
console.log('Listen on 3000')
})
```### Client
```js
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](https://www.conventionalcommits.org/).
For example:
- `feat(Server): something` for server feature.
- `fix(Client): something` for client bug fix.