Skip to content

medac-tfg/fastify-socket.io

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastify-socket.io

js-standard-style CI workflow

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

Supports Fastify versions 3.x

Install

npm i fastify-socket.io socket.io

Usage

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

const fastify = require('fastify')()

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

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

fastify.listen(3000)

For more details see examples

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.

Typescript

From v4 types will no longer be included in the plugin package but will need to be installed separately:

npm i -D types-fastify-socket.io

This is necessary to allow, eventually, the developer to be able to define custom types and make use of the socket.io new types system (doc).

Acknowledgements

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

License

Licensed under MIT.
socket.io license

About

Fastify plugin for Socket.io

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 77.9%
  • TypeScript 22.1%