Node.js battery module (deprecated)
Objective-C JavaScript Python Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
binding.gyp
getScript.js
install.sh
license.md
node-battery-linux.js
node-battery.mm
package.json
readme.md

readme.md

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.