相对较新的Node / Mongoose / Socket.io而且我被卡住了。我有一个运行的两个节点进程 - index.js和person_saver.js。当person_saver.js创建并保存一个人时,我想向连接到index.js的客户端发出一个事件。似乎它应该是直截了当的,但无法弄明白。帮助赞赏!
index.js
io.sockets.on('connection', function(client){
//Can person_saver.js use the client object from index.js?
//Alternately, can I trigger something here based on the person.save callback?
}
person_saver.js
var person = new Person({ first: 'Spider', last: 'Man', age: 23 });
person.save(function(err, person) {
//client.emit('person-event', person); ??
});