JSPM

fastify-plugin-socket.io

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q23967F
  • License MIT

Fastfiy Socket.io Plugin

Package Exports

  • fastify-plugin-socket.io
  • fastify-plugin-socket.io/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fastify-plugin-socket.io) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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