1.0.0 • Published 2 years ago

fastify-plugin-socket.io v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

fastify-plugin-socket.io

NPM

js-standard-style

fastify-plugin-socket.io enables the use of Socket.io in a Fastify application.

Install

yarn add fastify-plugin-socket.io

Usage

Require fastify-plugin-socket.io and register it as any other plugin, it will add a io decorator.

const fastify = require('fastify')()

fastify.register(require('fastify-plugin-socket.io'), {
  // put your socket.io options here
})

fastify.get('/', (req, reply) => {
  fastify.io.emit('hello world')
})

fastify.listen(3000)

You can use it as is without passing any option, or you can configure it as explained by Socket.io doc.

Hook

The plugin also adds an onClose hook which closes the socket server when the fastify instance is closed.

Acknowledgements

The code is a port for Fastify of socket.io.

License

Licensed under MIT. socket.io license