Acknowledgements in socket.io when using mongoose <p>I use <code>socket.io</code> to communicate between server and client.</p> <p>On the server, I have</p> <pre><code>socket.on('new object', (id, object) =&gt; { Model.findByIdAndUpdate(id, { $addToSet: { objects: object } }, { new: true }).then(model =&gt; { io.sockets.emit('new object', object); }).catch(err =&gt; { console.log(err); }); }); </code></pre> <p>So when a new object is created, I broadcast it to all sockets (including the sender).</p> <p>What I want is to tell the client who started this process from the client if everything was successful.</p> <p>I have found <a href="http://socket.io/docs/#sending-and-getting-data-(acknowledgements)" rel="nofollow">http://socket.io/docs/#sending-and-getting-data-(acknowledgements)</a>, but I don't know exactly how to do it.</p> <p>I guess I should do something like</p> <pre><code>socket.on('new object', (id, object, callbackFunction) =&gt; { Model.findByIdAndUpdate(id, { $addToSet: { objects: object } }, { new: true }).then(model =&gt; { callbackFunction('success'); io.sockets.emit('new object', object); }).catch(err =&gt; { callbackFunction('error'); }); }); </code></pre> <p>and on the client have</p> <pre><code>socket.emit('new object', id, object, function (msg) { alert(msg); }); </code></pre> <p>but is this correct? I guess there will be a problem of calling <code>callbackFunction</code> inside <code>then</code> and <code>catch</code>.</p>