node-batterydeprecated

Get battery information.

Usage no npm install needed!

<script type="module">
  import nodeBattery from 'https://cdn.skypack.dev/node-battery';
</script>

README

Node.js Battery Module

This module provides information on linux and osx about the power sources.

Usage

Node-battery provides two methods:

var nodeBattery = require("node-battery");

nodeBattery.getBatteries(function(data){

    // Linux only
    // "data" Is an array containing paths to the battery files
});

nodeBattery.percentages(function(data){

    // "data" Is an array containing a percentage of power left for each battery.
});

nodeBattery.isCharging(function(data){

    // "data" Is an array containing a 0 or a 1 depending on wheter the battery is being charged.
});

On Linux this module works by reading out the BAT* files in '/sys/class/power_supply'.

If no batteries are detected this could be caused by the fact that your BAT* files start with BAT0 instead of BAT1, to fix this just pass in a 0 as the second argument.