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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -