0.0.7 • Published 6 months ago

node-carbon v0.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

🌱 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 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);
MetricUnit
CPU Usagewatts
Elapsed Timeseconds
Memory Usage (RSS Delta)Mb
Memory Usage (Heap Total Delta)Mb
Memory Usage (Heap Used Delta)Mb
Carbon EmissiongCO2e/kWh

Functions

NameDescription
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.

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.

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago