Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Minimal example for using express-body-parser middleware
var express = require('express');
var app = express();
var http = require('http');
var server = http.createServer(app);
var xmlparser = require('express-xml-bodyparser');
// fyi: it'd be better to attach the parser to wanted routes only
app.use(xmlparser());'/xml', function(req, res, next) {
// req.body is an object, so we'll check if it has any (enumerable) properties
if (Object.keys(req.body).length) {
console.log('Parsed XML', req.body);
} else {
res.send('Not OK :(');
console.log('post body length', req.rawBody.length); // this is a string
return res.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment