I am working on a node project. In the following snippet of middleware, I need to remove the newlines from req.body to prepare it for sending inside a JSONP response.
server.use(function(req,res,next){
if(req.query.concat) {
req.body = req.body; // <--- HERE I need to remove the newlines, etc.
} else {
req.body = req.body || {};
req.body.jsonp_callback = req.query.callback;
}
next();
})
How can I get the req.body ready for JSONP?
The newline character in javascript is just like any other character and it’s denoted by ‘\n’. Use global replace: