Skip to content

This package calculates the carbon emission by the network traffic from a given URL.

License

Notifications You must be signed in to change notification settings

ricardodantas/website-carbon-calculator

Repository files navigation

Snyk Vulnerabilities for GitHub Repo CircleCI Codecov GitHub last commit GitHub top language node-current

🌳 Website Carbon Calculator

This package calculates the carbon emission by the network traffic from a given URL.

How to use

1. Install the package using NPM or YARN.

NPM

npm i website-carbon-calculator --save

YARN

yarn add website-carbon-calculator

2. Get you Google PageSpeed API Key here.

3. Import and use the lib

import { WebsiteCarbonCalculator, WebsiteCarbonCalculatorError } from 'website-carbon-calculator';

try {

  const websiteCarbonCalculator = new WebsiteCarbonCalculator({pagespeedApiKey: '...'});
  const result = websiteCarbonCalculator.calculateByURL('https://yourwebsite.com');

//   {
//     url: 'yourwebsite.com',
//     bytesTransferred: 123456,
//     isGreenHost: true,
//     co2PerPageview: 0.1234567,
//   }

} catch(error) {
  if(error instanceof WebsiteCarbonCalculatorError){
    console.warn(error.message);
  }
  // Do something else...
}


How it works

Check how the calc works here.

Sponsor

Help to maintain this project and become a sponsor on Github Sponsors, Ko-fi, or Buy Me A Coffee! 🎉 You can get your company logo, link & name on this file. It's also rendered on package page in npmjs.com and yarnpkg.com sites too! 🚀

Contributing

See CONTRIBUTING.

Author

Ricardo Dantas - @ricardodantas

Credits

This package based on the carbon emission calculator code available on the Website Carbon API by Wholegrain Digital.

License

MIT, see LICENSE