This is the official JS/TS SDK for the Open Food Facts API.
npm install @openfoodfacts/openfoodfacts-nodejs
npm install git+https://github.com/openfoodfacts/openfoodfacts-js.git
Be sure to read the Open Food Facts API documentation to understand how the API should be used and what data is available BEFORE starting to use the SDK.
Import the SDK in your project and create a client instance:
import OpenFoodFacts from "@openfoodfacts/openfoodfacts-nodejs";
// if you're on the browser, you can pass the fetch function as a parameter
const client = new OpenFoodFacts(window.fetch);
// or if you're on Node.js, you can pass the global fetch function
const client = new OpenFoodFacts(globalThis.fetch);
// or if you're using a custom fetch implementation
import fetch from "node-fetch";
const client = new OpenFoodFacts(fetch);
// then you can use the client to access the Open Food Facts API
client.getProduct("5000112546415").then((product) => {
console.log(product);
});
See the Open Food Facts API documentation for more details on the API endpoints.
See the SDK auto generated documentation for a complete list of available methods and classes.
The project uses openapi-typescript to generate the API bindings automatically from the OpenAPI specification.
To generate the API bindings, run yarn api
.
The files are to be committed to the repository, so that the SDK can be used without having to download the specs every time.
yarn install
in the directory.yarn build
to generate the OpenAPI bindings and build the project.yarn test
to run the tests.We accept contributions of any kind: new features, bug fixes, documentation improvements, etc.
You can also help us by reporting bugs, suggesting improvements or testing new features.
When submitting a PR, please use the angular commit guideline.
If you use this SDK, feel free to open a PR to add your application in this list.