https://github.com/ricardodantas/website-carbon-calculator
This package calculates the carbon emission by the network traffic from a given URL.
https://github.com/ricardodantas/website-carbon-calculator
carbon-calculator carbon-emissions carbon-footprint greentech nodejs typescript
Last synced: 3 months ago
JSON representation
This package calculates the carbon emission by the network traffic from a given URL.
- Host: GitHub
- URL: https://github.com/ricardodantas/website-carbon-calculator
- Owner: ricardodantas
- License: mit
- Created: 2021-04-22T19:52:27.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T09:38:00.000Z (over 2 years ago)
- Last Synced: 2024-11-04T03:32:35.620Z (8 months ago)
- Topics: carbon-calculator, carbon-emissions, carbon-footprint, greentech, nodejs, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/website-carbon-calculator
- Size: 1.82 MB
- Stars: 33
- Watchers: 2
- Forks: 8
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
     
# 🌳 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](https://developers.google.com/speed/docs/insights/v5/get-started#APIKey).
### 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](https://www.websitecarbon.com/how-does-it-work/).
## Sponsor
Help to maintain this project and become a sponsor on [Github Sponsors](https://github.com/sponsors/ricardodantas), [Ko-fi](https://ko-fi.com/ricardodantas), or [Buy Me A Coffee](https://www.buymeacoffee.com/ricardodantas)! 🎉 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](CONTRIBUTING.md).
## Author
Ricardo Dantas - [@ricardodantas](https://twitter.com/ricardodantas)
## Credits
This package based on the carbon emission calculator code available on the [Website Carbon API](https://gitlab.com/wholegrain/carbon-api-2-0/-/tree/master/) by [Wholegrain Digital](https://www.wholegraindigital.com/).
## License
MIT, see [LICENSE](LICENSE)