Mobile Monitoring Solutions

Close this search box.

CO2.js Helps Developers Track Their Application’s Carbon Footprint

MMS Founder
MMS Bruno Couriol

Article originally posted on InfoQ. Visit InfoQ

The Green Web Foundation published a new release of CO2.js, a JavaScript library that enables developers to access the Green Web API and estimate the carbon emissions associated with their apps, websites, and software. CO2.js supports developers who want to create a carbon budget for their site or include carbon footprint estimation in monitoring tools.

By some measures, internet use accounts for 3.7% of global greenhouse gas emissions, which makes it comparable to emissions associated with the entire world air traffic.

The Green Web Foundation explains:

Our mission at The Green Web Foundation is for a fossil-free internet by the year 2030. We know that getting there will take a collective effort on the part of technologists around the globe. That’s why we’re always looking for ways to leverage open source and open data. Our aim is to equip those in tech jobs with compelling, state-of-the-art, practical, and well-documented tools and “patterns” for change. Tools and patterns that can be used right now in workflows and products.

CO2.js is just one of the tools we’ve created to help with this.

CO2.js takes an input of data, in bytes, and returns an estimate of the carbon emissions produced to move that data over the internet. It can be run in the browser, on Node.js servers and some serverless and edge compute runtimes.

Developers can incorporate the carbon emission estimate in their workflow and set a carbon budget in the same way that they already set code coverage targets or performance budgets. If a website or an application goes over budget, an alert could be raised or the deployment could be blocked.

To estimate carbon emissions related to bytes of data, developers can choose between the OneByte model and the Sustainable Web Design model — a richer model that factors in the device type, network type, and CPU utilization:

import  { co2 }  from  "@tgwf/co2";

const swd =  new  co2();
const declaredSwd =  new  co2({  model:  "swd"  });

CO2.js also has a perVisit() function to calculate the carbon emissions of a website, Additionally, developers can check whether a domain is hosted on a green host by querying the Green Web Foundation API:

const  { hosting } = require("@tgwf/co2");

hosting.check(["", ""]).then((result) => {

CO2.js is open-sourced under the Apache license. Contributors and sponsors are welcome. The Green Web Foundation is a not-for-profit organization that maintains the world’s largest open dataset of websites that run on green energy. They also offer open-source tools to manage the environmental impact of digital services.

About the Author

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.