1.4.1 • Published 7 years ago

nutrient-data-laboratory v1.4.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Node.js | USDA Nutrient Data Laboratory API


Summary

Node.js API wrapper for the USDA Nutrient Data Laboratory REST API

For more information, visit https://ndb.nal.usda.gov/ndb/api/doc

Installation

npm install nutrient-data-laboratory --save

Usage

NutrientDataLaboratory#foodReports()

Parameters

ParameterRequiredDefaultDescription
api_keyyn/aMust be a data.gov registered API key
ndbnoyn/aNDB no. May send as a list of NDB nos. up to a maixum of 20 per request
typenb (basic)Report type: basic or full or stats
formatnJSONReport format: xml or json

Example

let ndl = new NutrientDataLaboratory('DEMO_KEY')

ndl.foodReports({
  ndbno: '01009',
  type: 'b'
}, (err, res) => {
  if (err) console.error(err)
  else console.log(res)
})

NutrientDataLaboratory#lists()

Parameters

ParameterRequiredDefaultDescription
api_keyyn/aMust be a data.gov registered API key
ltnflist type(lt): f = food , n = all nutrients, ns = speciality nutrients, nr = standard release nutrients only,g = food group
maxn50maximum number of items to return
offsetn0beginning item in the result set
sortnnsort order: n=name or id (Meaning of id varies by list type: nutrient number for a nutrient list, NDBno for a foods list ,food group id for a food group list
formatnJSONreport format: JSON or XML

Example

let ndl = new NutrientDataLaboratory('DEMO_KEY')

ndl.lists({
  lt: 'f',
  sort: 'n'
}, (err, res) => {
  if (err) console.error(err)
  else console.log(res)
})

NutrientDataLaboratory#nutrientReports()

Parameters

ParameterRequiredDefaultDescription
api_keyyn/aMust be a data.gov registered API key
fgn""limit your nutrients to one or more food groups by providing a list of food group ID's via the fg parameter. The default is a blank list meaning no food group filtering will be applied. Up to 10 food groups may be specified.
formatnJSONReport format: xml or json
maxn50Number of rows to return. The maximum per request is 1,500.
offsetn0beginning row in the result set to begin
nbnonn/aReport the nutrients for a single food identified by it's unique id -- nutrient number
nutrientsyn/aa list of up to a maximum of 20 nutrient_id's to include in the report
sortnfSort the list of foods by (f)ood name or nutrient (c)ontent. If you are requesting more than one nutrient and specifying sort = c then the first nutrient in your list is used for the content sort.
subsetn0You may indicate all the foods in the SR database or an abridged list from the pull down menu. Set the subset parameter to 1 for the abridged list of about 1,000 foods commonly consumed in the U.S. The default 0 for all of the foods in the database

Example

let ndl = new NutrientDataLaboratory('DEMO_KEY')

ndl.nutrientReports({
  nutrients: ['205', '204', '208', '269']
}, (err, res) => {
  if (err) console.error(err)
  else console.log(res)
})

NutrientDataLaboratory#search()

Parameters

ParameterRequiredDefaultDescription
api_keyyn/aMust be a data.gov registered API key
qn""Search terms
dsn""Data source. Must be either 'Branded Food Products' or 'Standard Reference'
fgn""Food group ID
sortnrSort the results by food name (n) or by search relevance (r)
maxn50maximum rows to return
offsetn0beginning row in the result set to begin
formatnJSONresults format: json or xml

Example

let ndl = new NutrientDataLaboratory('DEMO_KEY')

ndl.search({
  q: 'butter',
  max: 25,
  offset: 0
}, (err, res) => {
  if (err) console.error(err)
  else console.log(res)
})