Giter VIP home page Giter VIP logo

node-carbon's Introduction

๐ŸŒฑ Node Carbon: A Node Package for Measuring Carbon Footprints ๐ŸŒ

Ever pondered the environmental impact of your Node.js processes? Enter Node Carbon โ€“ your solution for calculating the carbon footprint of your current Node.js operations.

status NPM version NPM downloads MIT License Test Workflow

Why Measure Your Carbon Footprint? ๐ŸŒ

Understanding the carbon footprint of your Node.js processes is crucial for businesses, organizations, and individuals striving to minimize their environmental impact and enhance resource efficiency. As we collectively aim for a greener future, Node Carbon empowers you to make informed decisions and take proactive steps towards sustainability.

How Does Node Carbon Work? โš™๏ธ

Node Carbon estimates the electricity consumption of your hardware (CPU+RAM) and then applies the carbon intensity specific to the region where the computing is taking place. This comprehensive approach ensures that you get an accurate and localized assessment of your digital carbon footprint.

Carbon Emission Calculation

Key Features ๐Ÿ”

  1. Precision in Measurement: Node Carbon provides a detailed breakdown of electricity consumption, considering the specific hardware components involved in your Node.js processes.

  2. Regional Carbon Intensity: By factoring in the carbon intensity of the region where your computations occur, Node Carbon offers a nuanced understanding of the environmental impact.

  3. Empowering Sustainable Choices: Armed with insights from Node Carbon, you can make informed decisions to optimize resource usage, reduce energy consumption, and contribute to a more sustainable digital ecosystem.

Get Started Today! ๐Ÿš€

Ready to take the first step towards a greener digital footprint? Node Carbon is here to help. Calculate, analyze, and optimize your Node.js processes for a more sustainable future. Install node carbon.

npm install node-carbon --save-dev
yarn add node-carbon --dev # or yarn

Example

const nodeCarbon = new NodeCarbon();

// Get energy information about the current network provider
const energyInfo = await nodeCarbon.getEnergyInfo();
console.log("Energy info", energyInfo);

// start logging energy usage
await nodeCarbon.start();

setTimeout(async () => {
  // Stop carbon logging of current process
  const carbon = await nodeCarbon.stop();
  console.table({
  'CPU Usage (watts)': carbon.cpuUsageInfo.cpuUsage,
  'Total Time (s)': carbon.elapsedTime,
  'RSS Delta (Mb)': carbon.memoryUsageInfo.rssDeltaMB,
  'Heap Total Delta (Mb)': carbon.memoryUsageInfo.heapTotalDeltaMB,
  'Heap Used Delta (Mb)': carbon.memoryUsageInfo.heapUsedDeltaMB,
  'Carbon Consumption (gCO2e/kWh)': carbon.carbonEmission
});
}, 1000);
Metric Unit
CPU Usage watts
Elapsed Time seconds
Memory Usage (RSS Delta) Mb
Memory Usage (Heap Total Delta) Mb
Memory Usage (Heap Used Delta) Mb
Carbon Emission gCO2e/kWh

Functions

Name Description
getEnergyInfo() Gives information about the energy grid of the connected network and its composition.
start() Starts logging the hardware energy consumption.
end() Computes the carbon emission based on the computation power usage and regional carbon intensity.
startMeasurementWithInterval(milliseconds) Measures carbon consumption in an interval (milliseconds).
stopPowerMeasurement() Clear the timer interval set in startMeasurementWithInterval().

Testing

 yarn test

Experiments

Experiments with different packages are done here.

Support

This package supports Node.js versions between >= 16.0.0 and <= 21.0.0. Here's an experimental setup with various version.

TODOs

  • Develop a more effective method for measuring the power consumption of RAM.

Contributing

  1. Fork and clone it
  2. Install dependencies: npm install
  3. Create a feature branch: git checkout -b new-feature
  4. Commit changes: git commit -am 'Added a feature'
  5. Run static code analysis and unit tests: npm test
  6. Push to the remote branch: git push origin new-feature
  7. Create a new Pull Request

License

Code released under the MIT license.

node-carbon's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

shrsyas

node-carbon's Issues

Carbon Intensity Usage Info

It would be nice to show carbon intensity usage along with the composition of the connected network. Is it ok if I work on this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.