Member-only story
Calculate Carbon Emissions with CO2.js: A Quick Tutorial
Learn how to estimate the carbon footprint of your digital data transfers using the CO2.js library in this step-by-step guide.
CO2.js is an open-source JavaScript library designed to estimate the carbon emissions produced by data transferred over the internet. Whether you’re a developer concerned with sustainability or just curious about the carbon impact of your website, CO2.js offers an accessible way to track digital carbon footprints. In this article, we will walk through an example of how to use CO2.js in the browser.
Installation
There are multiple ways to get CO2.js installed, depending on your project setup. Here are the most common approaches:
1. Using NPM (Node Package Manager)
For projects using NPM, you can install CO2.js as a dependency by running the following command:
npm install @tgwf/co2
2. Using a CDN (Content Delivery Network)
For projects that don’t use Node.js or NPM, you can import CO2.js directly in the browser via Skypack:
import tgwf from "https://cdn.skypack.dev/@tgwf/co2";