I'm trying to create an HTTP server where it will use bodyParser()
to request the middleware
part before the handlers
. But when trying to use it in code, it indicates error saying that it is not defined.
My code:
var http = require('http');
var connect = require('connect');
var logger = require('morgan');
var app = connect();
// setup the middlewares
app.use(logger(':method :req[content-type]'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// actually respond
app.use(function(req, res) {
res.end(JSON.stringify(req.body));
});
http.createServer(app).listen(8080);
bodyParser is not defined
I'm using the bodyParser()
part as indicated by current documentation and even by other sites when talking about it. But it's still not working. What could be making this mistake?