co2-compensator

0.1.2 • Public • Published

Original Readme of CO2 JS Package of The Green Web Foundation

CO2

We know computers use electricity, and because most of the electricity we use comes from burning fossil fuels to generate, there is an environmental cost to every upload and download we make over the internet.

We cando something about this though. The same way we use performance budgets make apps and website faster and cheaper to run, we can use carbon budgets to make them faster, cheaper and greener.

The CO2 package from [The Green Web Foundation][tgwf] lets you quickly estimate these emissions, to make measurable improvements as part of your workflow.

It does this by implementing the 1byte model as used by the Shift Project, as introduced in their report on CO2 emissions from digital infrastructure, [Lean ICT: for a sober digital][soberDigital], to return a number for the estimated CO2 emissions for the corresponding number of bytes sent over the wire.

It is currently used in the web performance tool [sitespeed.io][], to help developers build greener, more planet friendly digital services.

If you want to build this kind of environmental information into your own software, and want some advice, we'd be happy to hear from you - please open an issue, remembering to link to your project.

This is open source software, with all the guarantees associated, so if you want professional advice, to a deadline, and you have a budget please see the services offered by the [Green Web Foundation][tgwf-services].

Installation

npm i -g co2-compensator

Usage

Comand Line (CLI)

co2-compensator <MB>  

Specify the MB to compensate.

Calculating emissions per byte

Server-side

This approach relies on the fs module and so can only be used on platforms, like node.js, that support this.

const CO2 = require('@tgwf/co2')
const bytesSent = (1024 * 1024 * 1024)
const co2Emission = new CO2();
estimatedCO2 = co2Emission.perByte(bytesSent)

console.log(`Sending a gigabyte, had a carbon footprint of ${estimatedCO2.toFixed(3)} grams of CO2`)

Browser-side

For browser-based solutions, you must import the co2.js submodule directly from node_modules. For example, like this:

const CO2 = require('node_modules/@tgwf/co2/src/co2.js')
const bytesSent = (1024 * 1024 * 1024)
const co2Emission = new CO2();
estimatedCO2 = co2Emission.perByte(bytesSent)

console.log(`Sending a gigabyte, had a carbon footprint of ${estimatedCO2.toFixed(3)} grams of CO2`)

Checking for green power

Because different digital services and websites use different forms of power, there is also a module for checking if a domain uses green power or not, and whether the domains linked to on a page use green power as well.

const greencheck = require('@tgwf/hosting')

// returns true if green, otherwise false
greencheck.check("google.com")

// returns an array of the green domains, in this case ["google.com"].
greencheck.check(["google.com", "kochindustries.com"])]

// returns an array of green domains, again in this case, ["google.com"]
greencheck.checkPage(["google.com"])

Notes

Please note, we currently look at just the carbon cost of generating the electricity, similar to how the IEA does, not the full life cycle cost of the energy.

Doing this would include things like:

  • the carbon emitted when carrying out activity associated with digging up the fuel
  • the carbon associated with mining the materials to build the power stations, datacentres, and so on
  • the end of life costs
  • the maintenance costs over the life of the datacentres, power generation and end user devices, and the rest of the internet

Life cycle figures do exist, but they are very difficult to do well. If you're interested in contributing to this. we'd love to hear from you.

Licenses

Apache 2.0

Package Sidebar

Install

npm i co2-compensator

Weekly Downloads

0

Version

0.1.2

License

Apache-2.0

Unpacked Size

16.8 MB

Total Files

24

Last publish

Collaborators

  • stromdao