CopyPastor

Detecting plagiarism made easy.

Score: 0.8082016110420227; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2021-01-11
by ZaO Lover

Original Post

Original - Posted on 2012-12-08
by Mark Bonano



            
Present in both answers; Present only in the new answer; Present only in the old answer;

`express.bodyParser()` is no longer bundled as part of express. You need to install it separately before loading: ``` npm i body-parser
// then in your app var express = require('express') var bodyParser = require('body-parser') var app = express() // create application/json parser var jsonParser = bodyParser.json() // create application/x-www-form-urlencoded parser var urlencodedParser = bodyParser.urlencoded({ extended: false }) // POST /login gets urlencoded bodies app.post('/login', urlencodedParser, function (req, res) { res.send('welcome, ' + req.body.username) }) // POST /api/users gets JSON bodies app.post('/api/users', jsonParser, function (req, res) { // create user in req.body }) ``` You can check more details here.(https://www.npmjs.com/package/body-parser)
**original follows**
You must make sure that you define all configurations BEFORE defining routes. If you do so, you can continue to use `express.bodyParser()`.
An example is as follows: ``` var express = require('express'), app = express(), port = parseInt(process.env.PORT, 10) || 8080;
app.configure(function(){ app.use(express.bodyParser()); app.use(app.router); });
app.listen(port); app.post("/someRoute", function(req, res) { console.log(req.body); res.send({ status: 'SUCCESS' }); }); ```
## UPDATE July 2020
`express.bodyParser()` is no longer bundled as part of express. You need to install it separately before loading:
``` npm i body-parser
// then in your app var express = require('express') var bodyParser = require('body-parser') var app = express() // create application/json parser var jsonParser = bodyParser.json() // create application/x-www-form-urlencoded parser var urlencodedParser = bodyParser.urlencoded({ extended: false }) // POST /login gets urlencoded bodies app.post('/login', urlencodedParser, function (req, res) { res.send('welcome, ' + req.body.username) }) // POST /api/users gets JSON bodies app.post('/api/users', jsonParser, function (req, res) { // create user in req.body }) ```

See [here][1] for further info
## original follows
You must make sure that you define all configurations BEFORE defining routes. If you do so, you can continue to use `express.bodyParser()`.
An example is as follows:
var express = require('express'), app = express(), port = parseInt(process.env.PORT, 10) || 8080; app.configure(function(){ app.use(express.bodyParser()); app.use(app.router); }); app.listen(port); app.post("/someRoute", function(req, res) { console.log(req.body); res.send({ status: 'SUCCESS' }); });

[1]: https://www.npmjs.com/package/body-parser

        
Present in both answers; Present only in the new answer; Present only in the old answer;