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
Parameter | Required | Default | Description |
---|---|---|---|
api_key | y | n/a | Must be a data.gov registered API key |
ndbno | y | n/a | NDB no. May send as a list of NDB nos. up to a maixum of 20 per request |
type | n | b (basic) | Report type: [b]asic or [f]ull or [s]tats |
format | n | JSON | Report format: xml or json |
Example
let ndl = 'DEMO_KEY' ndl
NutrientDataLaboratory#lists()
Parameters
Parameter | Required | Default | Description |
---|---|---|---|
api_key | y | n/a | Must be a data.gov registered API key |
lt | n | f | list type(lt): f = food , n = all nutrients, ns = speciality nutrients, nr = standard release nutrients only,g = food group |
max | n | 50 | maximum number of items to return |
offset | n | 0 | beginning item in the result set |
sort | n | n | sort 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 |
format | n | JSON | report format: JSON or XML |
Example
let ndl = 'DEMO_KEY' ndl
NutrientDataLaboratory#nutrientReports()
Parameters
Parameter | Required | Default | Description |
---|---|---|---|
api_key | y | n/a | Must be a data.gov registered API key |
fg | n | "" | 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. |
format | n | JSON | Report format: xml or json |
max | n | 50 | Number of rows to return. The maximum per request is 1,500. |
offset | n | 0 | beginning row in the result set to begin |
nbno | n | n/a | Report the nutrients for a single food identified by it's unique id -- nutrient number |
nutrients | y | n/a | a list of up to a maximum of 20 nutrient_id's to include in the report |
sort | n | f | Sort 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. |
subset | n | 0 | You 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 = 'DEMO_KEY' ndl
NutrientDataLaboratory#search()
Parameters
Parameter | Required | Default | Description |
---|---|---|---|
api_key | y | n/a | Must be a data.gov registered API key |
q | n | "" | Search terms |
ds | n | "" | Data source. Must be either 'Branded Food Products' or 'Standard Reference' |
fg | n | "" | Food group ID |
sort | n | r | Sort the results by food name (n) or by search relevance (r) |
max | n | 50 | maximum rows to return |
offset | n | 0 | beginning row in the result set to begin |
format | n | JSON | results format: json or xml |
Example
let ndl = 'DEMO_KEY' ndl