Skip to content

Node.js client and API types for USDA FoodData Central

License

Notifications You must be signed in to change notification settings

metonym/fooddata-central

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fooddata-central

NPM Build

Node.js client and API types for USDA FoodData Central.

FoodData Central is an API provided by the U.S. Department of Agriculture that provides expanded nutrient profile data for foods.

Getting Started

yarn add fooddata-central

Prerequisites

An API key is required to interact with the FoodData Central API.

Usage

import Client from "fooddata-central";

(async () => {
  // initialize a new client
  const client = new Client({ api_key: "API_KEY" });

  // search foods based on an input
  const results = await client.search({ generalSearchInput: "raw broccoli" });

  if (results.success) {
    // get details for food item
    const details = await client.details(results.data.foods[0].fdcId);

    if (details.success) {
      console.log(details.data);
    }
  }
})();

API

Search foods

Search the food database using the search method.

client.search({
  generalSearchInput?: string;
  includeDataTypeList?: string | string[];
  ingredients?: string;
  brandOwner?: string;
  requireAllWords?: boolean;
  pageNumber?: number;
  sortField?: "lowercaseDescription.keyword" | "dataType.keyword" | "publishedDate" | "fdcId";
  sortDirection?: "asc" | "desc";
})

Retrieve food details

Each food object returned from the search endpoint contains a unique fdcId.

Pass the fdcId value to the details method to retrieve the nutrient profile of the item.

client.details(fdcId: number)

License

MIT

About

Node.js client and API types for USDA FoodData Central

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published