Skip to content

Instantly share code, notes, and snippets.

@catacs
Last active April 22, 2017 19:34
Show Gist options
  • Save catacs/fd01a482118c282b82ffeb01f418c535 to your computer and use it in GitHub Desktop.
Save catacs/fd01a482118c282b82ffeb01f418c535 to your computer and use it in GitHub Desktop.
How to get body parameters in node.js
const bodyParser = require('body-parser');
const express = require('express');
const app = express();
const multer = require('multer');
const upload = multer();
app.use(bodyParser.json());
var router = express.Router();
router.get('/helloWorld', function(req, res) {
res.json({ message: 'I am groot!' });
});
router.post('/helloWorld', upload.array(), function(req, res) {
console.log('Auth request recieved');
// Get the user name
var user = req.body.is_test;
var aToken = 'a_token'; //getToken(user);
res.json({ token: aToken });
});
app.use('/', router);
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment