18.05.2016 Views

Mittwoch, 18. Mai, 2016

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MongoDB CRUD the MVC way with Passport Authentication 57<br />

You need install the body-parser¹¹¹ module which provides several middlewares to handle request<br />

data, and you can do that by executing the following command:<br />

1 $ npm install body-parser --save<br />

After this, update your express.js file to look like this:<br />

1 var config = require('./config'),<br />

2 express = require('express'),<br />

3 bodyParser = require('body-parser');<br />

4<br />

5 module.exports = function() {<br />

6 var app = express();<br />

7<br />

8 app.use(bodyParser.urlencoded({<br />

9 extended: true<br />

10 }));<br />

11<br />

12 app.use(bodyParser.json());<br />

13<br />

14 app.set('views', './app/views');<br />

15 app.set('view engine', 'ejs');<br />

16<br />

17 require('../app/routes/index.server.routes.js')(app);<br />

18 require('../app/routes/users.server.routes.js')(app);<br />

19<br />

20 app.use(express.static('./public'));<br />

21<br />

22 return app;<br />

23 };<br />

If you run node server now and try to POST the data again with Postman, you will see something<br />

like:<br />

¹¹¹https://github.com/expressjs/body-parser

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!