CO2.js v0.19 introduces the ability for developers to lookup a domain for the presence and contents of a carbon.txt using the Green Web Foundation carbon.txt API.
Perform carbon.txt lookups with Co2.js
Recently, we made our carbon.txt API public allowing anyone to look up, parse and validate carbon.txt files in their own applications.
In this release of CO2.js, we introduce the ability for developers to lookup a web domain using our carbon.txt API. This allows developers to quickly check for the existence of a carbon.txt file on a given domain, and if one is found then returns the contents of that file in a JSON format. This mirrors the green hosting check functionality which has existed in CO2.js since 2019.
We’re written a full tutorial on our developer docs site – Check a domain for carbon.txt. Below is a quick code example showing a simple lookup.
import { check } from "@tgwf/co2/carbon-txt";
const result = await check("thegreenwebfoundation.org", {
apiKey: "an-api-key"
});
console.log(result);
// Returns
//
// {
// success: true,
// url: 'https://thegreenwebfoundation.org/carbon.txt',
// org: { disclosures: [ [Object], [Object] ] },
// upstream: { services: [ [Object], [Object], [Object], [Object], [Object] ] }
// }NOTE: To perform carbon.txt lookups in CO2.js, you will require a free carbon.txt API key. Get one by logging into the Green Web Portal.
To stay up-to-date with releases and CO2.js news, you can also subscribe to our mailing list.
You can find details of every release for CO2.js on GitHub, where you’ll also be able find the changelog for this project.
