Last active
December 16, 2016 22:40
-
-
Save adg29/71a039139037cb775810522a669edce5 to your computer and use it in GitHub Desktop.
express server rendering nutritionix fooditem JSON response after request-promise request
This file contains hidden or 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 rp = require('request-promise') | |
| var bodyParser = require("body-parser"); | |
| var app = express() | |
| app.use(bodyParser.urlencoded({extended: true})); | |
| app.use(bodyParser.json()); | |
| app.get('/:fooditem', function(req, res) { | |
| rp({ | |
| uri: 'https://api.nutritionix.com/v1_1/search', | |
| qs: { | |
| q: req.params.fooditem, | |
| appId: '', | |
| appKey: '' | |
| }, | |
| json: true | |
| }) | |
| .then(function(data) { | |
| res.send(data) | |
| }) | |
| .catch(function(err) { | |
| console.log(err) | |
| res.send('error') | |
| }) | |
| }) | |
| app.listen(3000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment