• Stars
    star
    406
  • Rank 106,421 (Top 3 %)
  • Language
    JavaScript
  • License
    Other
  • Created almost 5 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An npm module for accessing the green web API, and estimating the carbon emissions from using digital services

CO2.js

All Contributors

One day, the internet will be powered by renewable energy. Until that day comes, there’ll be a CO2 cost that comes with every byte of data that’s uploaded or downloaded. By being able to calculate these emissions, developers can be empowered to create more efficient, lower carbon apps, websites, and software.

Documentation | Changelog | Roadmap

What is CO2.js?

CO2.js is a JavaScript library that enables developers a way to estimate the emissions related to use of their apps, websites, and software.

Why use it?

Being able to estimate the CO2 emissions associated with digital activities can be of benefit to both developers and users.

Internally, you may want to use this library to create a carbon budget for your site or app. It is also useful for inclusion in dashboards and monitoring tools.

For user facing applications, CO2.js could be used to check & block the uploading of carbon intensive files. Or, to present users with information about the carbon impact of their online activities (such as browsing a website).

The above a just a few examples of the many and varied ways CO2.js can be applied to provide carbon estimates for data transfer. If you’re using CO2.js in production we’d love to hear how! Contact us via our website.

Installation

Using NPM

You can install CO2.js as a dependency for your projects using NPM.

npm install @tgwf/co2

Using Skypack

You can import the CO2.js library into projects using Skypack.

import tgwf from "https://cdn.skypack.dev/@tgwf/co2";

Using a JS CDN

You can get the latest version of CO2.js using one of the content delivery networks below.

jsDelivr

You can find the package at https://www.jsdelivr.com/package/npm/@tgwf/co2.

  • CommonJS compatible build https://cdn.jsdelivr.net/npm/@tgwf/co2@latest/dist/cjs/index-node.min.js
  • ES Modules compatible build https://cdn.jsdelivr.net/npm/@tgwf/co2@latest/dist/esm/index.js
  • IIFE compatible build https://cdn.jsdelivr.net/npm/@tgwf/co2@latest/dist/iife/index.js

Unpkgd

You can find the package at https://unpkg.com/browse/@tgwf/co2@latest/.

  • CommonJS compatible build https://unpkg.com/@tgwf/co2@latest/dist/cjs/index-node.min.js
  • ES Modules compatible build https://unpkg.com/@tgwf/co2@latest/dist/esm/index.js
  • IIFE compatible build https://unpkg.com/@tgwf/co2@latest/dist/iife/index.js

Build it yourself

You can also build the CO2.js library from the source code. To do this:

  1. Go to the CO2.js repository on GitHub.

  2. Clone or fork the repository.

  3. Navigate to the folder on your machine and run npm run build in your terminal.

  4. Once the build has finished running, you will find a /dist folder has been created. Inside you can find:

    • dist/cjs - A CommonJS compatible build.
    • dist/esm - An ES Modules compatible build.
    • dist/iife - An Immediately Invoked Function Expression (IIFE) version of the library.

Marginal and average emissions intensity data

CO2.js includes yearly average grid intensity data from Ember, as well as marginal intensity data from the UNFCCC (United Nations Framework Convention on Climate Change). You can find the data in JSON and CommonJS Module format in the data/output folder.

Using emissions intensity data

You can import annual, country-level marginal or average grid intensity data into your projects directly from CO2.js. For example, if we wanted to use the average grid intensity for Australia in our project, we could use the code below:

import { averageIntensity } from "@tgwf/co2";
const { data } = averageIntensity;
const { AUS } = data;
console.log({ AUS });

All countries are represented by their respective Alpha-3 ISO country code.

Publishing to NPM

We use np to publish new versions of this library to NPM. To do this:

  1. First login to NPM by running the npm login command in your terminal.
  2. Then run npx np <VERSION>.
  3. np will run several automated steps to publish the new package to NPM.
  4. If everything runs successfully, you can then add release notes to GitHub for the newly published package.

Release communication

CO2.js releases will be communicated through the following channels:

Channel Minor Release (0.xx) Patch Release (0.xx.x)
Github βœ… βœ…
Green Web Foundation website βœ… ❌
W3C Slack Sustainability Channel βœ… ❌
ClimateAction.Tech Slack βœ… ❌
Green Web Foundation LinkedIn Account βœ… ❌

Licenses

The code for CO2.js is licensed Apache 2.0. (What does this mean?)

The average carbon intensity data from Ember is published under the Creative Commons ShareAlike Attribution Licence (CC BY-SA 4.0). (What does this mean?)

The marginal intensity data is published by the Green Web Foundation, under the Creative Commons ShareAlike Attribution Licence (CC BY-SA 4.0). (What does this mean?)

See LICENCE for more.

Contributors

Chris Adams
Chris Adams

πŸ’»
fershad
fershad

πŸ’» πŸ“– 🚧
Peter Hedenskog
Peter Hedenskog

πŸ’»
Dryden
Dryden

πŸ’»
Evan Hahn
Evan Hahn

πŸ’» ⚠️
Prathum Pandey
Prathum Pandey

πŸ› πŸ’»
Frazer Smith
Frazer Smith

πŸ’» ⚠️
Hamish Fagg
Hamish Fagg

πŸ’»
Atul Varma
Atul Varma

πŸ’»
Piper
Piper

πŸ’»
Raymundo VΓ‘squez Ruiz
Raymundo VΓ‘squez Ruiz

πŸ’»
JamieB
JamieB

πŸ’»

More Repositories

1

green-cost-explorer

See how much of your cloud bill is spent on fossil fuels ,so you can do the right thing and switch. We're in a climate crisis, remember?
JavaScript
172
star
2

carbon.txt

A proposed convention for making it possible demonstrate that your infrastucture uses green power
74
star
3

grid-intensity-go

A tool written in go to help you factor carbon intensity into decisions about where and when to run computing jobs.
Go
61
star
4

lighthouse-plugin-greenhouse

Lighthouse, but for running sites on renewable power instead of fossil fuels
JavaScript
56
star
5

sustainability-policy

An creative commons licensed sustainability policy, to use as a starting point in your own organisation.
35
star
6

admin-portal

The member portal and platform powering The Green Web Foundation
Python
23
star
7

web-extension

The Green Web Addon based on Web Extensions
JavaScript
12
star
8

grid-intensity

A simple API to build awareness of carbon intensity into javascript programs
JavaScript
11
star
9

greenhouse-ci

Lighthouse CI, but checking for fossil fuels too, and available over an API and running in containers
JavaScript
10
star
10

greencheck-api

The green web foundation API
PHP
9
star
11

greenspeed

A repo designed to be forked, as an experiment in running github actions to git-scrape sites for record how well they perform in terms of accessibility, performance, and carbon emissions from data transfer
7
star
12

url2green-js

An npm module for quickly checking a domain against the The Green Web Foundation url2green dataset
JavaScript
6
star
13

grid-intensity-exporter

A grid intensity exporter for use with prometheus. Designed to be used for understanding carbon footprint of compute.
Go
6
star
14

greentrace

A electron based app to trace how packets of data traverse the internet, showing which bits use fossil fuels and which don't
JavaScript
3
star
15

greenhouse

Lighthouse, but for running sites on renewable power instead of fossil fuels
Jupyter Notebook
3
star
16

website-audit-work

Code snippets used for carrying out website audits using lighthouse
JavaScript
3
star
17

developer-docs

The developer documentation site for The Green Web Foundations open source libraries.
Nunjucks
2
star
18

carbon-txt-site

The public website for carbon.txt
Svelte
1
star
19

greenflow

A CLI tool to help understand how network traffic moves across the real world, what powers it, its CO2 footprint
Python
1
star
20

GWF-brand-assets

Assets for use when creating Green Web Foundation stuff like browser extensions, presentations and so on
1
star
21

carbon-txt-validator

A validator for carbon.txt files, and linked documents in them
Python
1
star