View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page

Sockets (sails.sockets)


Sails exposes several methods (sails.sockets.*) which provide a simple interface for realtime communication with connected socket clients. This is useful for pushing events and data to connected clients in realtime, rather than waiting for them to actively request it using HTTP. This is true regardless of whether a client sockets was connected from a browser tab, from an iOS app, or even from your favorite household IoT appliance.

These methods are implemented using a built-in instance of, which is available directly as (see below). However, in almost every case, you should call the sails.sockets.* methods (either directly, or via a higher level abstraction such as resourceful pubsub methods).

The API exposed by the sails.sockets.* methods is flexible enough out of the box to cover the requirements of most applications, and using them will future-proof your app against possible changes in the underlying implementation. However, if you are working on bringing some legacy code from a vanilla app into your Sails app, it can be useful to talk to directly. To accomplish this, Sails provides raw access to the underlying singleton (io) as See the docs for more information, and if you go this route, please proceed with care.

As of v0.11.4, Sails bundles [email protected] as a dependency of sails-hook-sockets, a core hook.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.


We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book