Created
November 16, 2015 18:51
-
-
Save codementum/edf5c44c3754756c6dde to your computer and use it in GitHub Desktop.
An easy way to parse POST request body with Express
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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