npm install nutritionix --save
// Require inside your project
var NutritionixClient = require('nutritionix');
var nutritionix = new NutritionixClient({
appId: 'YOUR_APP_ID',
appKey: 'YOUR_APP_KEY'
// debug: true, // defaults to false
});
// This will perform a fuzzy autocomplete query and return suggestions
nutritionix.autocomplete({ q: 'chedar che' })
.then(successHandler, errorHandler)
.catch(uncaughtExceptionHandler);
var ingredients = [
'1 tbsp sugar',
'1 red pepper'
];
// ensure you are passing a string with queries delimited by new lines.
nutritionix.natural(ingredients.join('\n'))
.then(successHandler, errorHandler)
.catch(uncaughtExceptionHandler);
// this will locate an item by its (id, resource_id, or upc)
nutritionix.item({ id: 'zgcjnYV' })
.then(successHandler, errorHandler)
.catch(uncaughtExceptionHandler);
;
// this will locate a brand by its id
nutritionix.brand({ id: 'bV'})
.then(successHandler, errorHandler)
.catch(uncaughtExceptionHandler);
// This will perform a search. The object passed into this function
// can contain all the perameters the API accepts in the `POST /v2/search` endpoint
nutritionix.search.standard({
q:'salad',
// use these for paging
limit: 10,
offset: 0,
// controls the basic nutrient returned in search
search_nutrient: 'calories'
}).then(successHandler, errorHandler)
.catch(uncaughtExceptionHandler);
// This will perform a search. The object passed into this function
// can contain all the perameters the API accepts in the `GET /v2/search/brands` endpoint
nutritionix.brand_search({
q: 'just salad',
limit: 10,
offset: 0,
type: 1 // (1:restaurant, 2:cpg, 3:usda/nutritionix) defaults to undefined
}).then(successHandler, errorHandler)
.catch(uncaughtExceptionHandler);
Take a look tests/index.js
for an end to end usecase for these libraries.