Last active
April 22, 2017 19:34
-
-
Save catacs/fd01a482118c282b82ffeb01f418c535 to your computer and use it in GitHub Desktop.
How to get body parameters in node.js
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
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