Skip to content

Instantly share code, notes, and snippets.

@codementum
Created November 16, 2015 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codementum/edf5c44c3754756c6dde to your computer and use it in GitHub Desktop.
Save codementum/edf5c44c3754756c6dde to your computer and use it in GitHub Desktop.
An easy way to parse POST request body with Express
var express = require('express');
var path = require('path');
// Get this by running `npm install body-parser`
var bodyParser = require('body-parser')
var app = express();
var port = process.env.PORT || 3000;
// Add this to support URL-encoded bodies
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static(path.join(__dirname, '/public')));
app.post('/movie', function(req, res) {
// Now it outputs a JSON object
console.log(req.body);
res.send('Successful POST!');
});
app.listen(port, function() {
console.log('App is listening on port ' + port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment