generator-angular-fullstack
generator-angular-fullstack copied to clipboard
Sockets emit into a function Controller
Hello I am trying to do socket.emit("notification", "Here is de json for notificacion"); some like that from a custom method like:
exports.uploadFile = function(req, res) {
var uploaded = {};
req.file('file').upload({
adapter: require('skipper-gridfs'),
uri: 'mongodb://localhost:27017/storage-dev.files'
}, function (err, uploadedFiles) {
if (err)
return res.send(500, err);
socket.emit("notification", "Here is de json for notificacion"); ////// HERE IS THE SOCKET
return res.status(200).send(uploadedFiles);
});
};
My problem is how to import socket.io that has been created on app.js Thanks. Greetings
I would use an EventEmitter.... or use the hook on the model after save/update
The app is available on the request object, so simply change socket.emit(.......) to req.app.socket.emit(.......)
req.app.socket is failing. Can you please help @victorhugoviiii