
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
fastify-ws
Advanced tools
Basic WebSocket support for Fastify built on the ws and uws libraries.
WebSocket support for Fastify built on the ws and uws libraries.
In server.js
:
'use strict'
const fastify = require('fastify')()
fastify.register(require('fastify-ws'))
fastify.ready(err => {
if (err) throw err
console.log('Server started.')
fastify.ws
.on('connection', socket => {
console.log('Client connected.')
socket.on('message', msg => socket.send(msg)) // Creates an echo server
socket.on('close', () => console.log('Client disconnected.'))
})
})
fastify.listen(34567)
Then run node server.js
and navigate to http://localhost:34567
in your browser. In the browser's JavaScript console, open a client-side WebSocket connection:
const host = location.origin.replace(/^http/, 'ws')
const ws = new WebSocket(host)
ws.onmessage = msg => console.log(msg.data)
Then, still in the browser console, send some messages to the server and watch as they're echoed back to you:
ws.send('WebSockets are awesome!')
// => undefined
// LOG: WebSockets are awesome!
The creator of uws
has ceased development on uws
and started working on their new project, uWebSockets.js. If you want high-performance web socket support in Fastify, the last real release of uws
(10.148.1) is probably your best bet, but given that it is now an abandoned project I can't recommend anyone use it for any non-throwaway projects. If you're using this library, I'd recommend you stick with the default ws
option.
In addition, if you choose to use uws
as your WebSocket library, ensure that you have configured your system properly and understand that the API is a slightly reduced subset of ws
's.
Licensed under MIT.
FAQs
Basic WebSocket support for Fastify built on the ws and uws libraries.
The npm package fastify-ws receives a total of 211 weekly downloads. As such, fastify-ws popularity was classified as not popular.
We found that fastify-ws demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.