View our GitHub

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

Edit Page

.message( models,data, [request] )


Publishes a custom message to a model’s subscribers.

Description Accepted Data Types Required ?
1 Record (or ID of record) to send message to int, string, object Yes
2 Message payload object Yes
3 Request request object No

message() emits a socket message using the model identity as the event name. The message is broadcast to all sockets subscribed to the model instance via the .subscribe model method.

The socket message is an object with the following properties:

  • id - the id attribute of the model instance
  • verb - "messaged" (a string)
  • data - the message payload


Arbitrary data to send to the subscribed sockets.


If this argument is included then the socket attached to that request will not receive the notification.


Find a user in the sails controller by name and send a socket message back to the client. This object can contain any data you want.

User.findOne({name: 'Bob'}).then(function(foundUser){
  User.message(foundUser, {count: 12, hairColor: 'red'});

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