Skip to content

Instantly share code, notes, and snippets.

@adg29
Last active December 16, 2016 22:40
Show Gist options
  • Select an option

  • Save adg29/71a039139037cb775810522a669edce5 to your computer and use it in GitHub Desktop.

Select an option

Save adg29/71a039139037cb775810522a669edce5 to your computer and use it in GitHub Desktop.
express server rendering nutritionix fooditem JSON response after request-promise request
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