javascript - How to listen to socket events and http post ? node js -
i working on node js server use socket io.
var express = require('express') app = express.createserver(); app.use(function(req, res, next) { res.header("access-control-allow-origin", "*"); res.header("access-control-allow-methods", "get,put,post,delete"); res.header("access-control-allow-headers", "origin, x-requested-with, content-type, accept, x-auth-token"); next(); }); app.get("/", function(req, res) {res.send('admin')});
i need listen post request json body i've added these lines:
app.post('/testpost',function(req,res){ console.log("post json : " + req.body ); });
but receiving undefined request body. because should add :
app.use(bodyparser.json()); app.use(bodyparser.urlencoded({ extended: true }));
but after adding bodyparser.json() socket io doesn't connect !
what should ? how ask node js use bodyparser.urlencoded /testpost route ?
Comments
Post a Comment