node.js - Handle POST in express with mongoDB and socket.io -
i have strange question , try explain it: send post request server , save body in db functions have exported in seperate file. how can emit saved via socket, since cannot require('socket.io') in ./database.js ?
here's snippet:
var app = require('express')(); var database = require('./database'); var serv = require('http').createserver(app); var socket = require('socket.io')(serv); .... app.post('/test', function(req, res){ database.save(model, req.body, res); //it saves body mongo , works *edit//if paste code of database.save() here can invoke emit //here want emit same data //if use following receiving error: can't set headers after sent. socket.emit('value', json.stringify(req.body)); };
Comments
Post a Comment