1
\$\begingroup\$

It's the first time managing Mongoose by socket.io and I'm wondering if this could be a good way:

socket.on('comment sent', function(data){
    var comment = new Comment(data);
    comment.save(function(err) {
        if (err) {
            //may be better send a custom error
            return io.emit('comment error',err);
        }
        io.emit('comment added',comment);
    });
});
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.