xsys

A node.js binding to useful system-level functions

Description

A node.js binding to useful system-level functions.

Requirements

Install

npm install xsys

Examples

  • Get filesystem total/free/used byte counts:
  var fs = require('xsys').fs;
 
  // format our numerical output 
  function fmtBytes(val) {
      return val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  }
 
  fs.getTotal(function(errn) {
      if (err) throw err;
      console.log('Total bytes for current volume: ' + fmtBytes(n));
  });
  fs.getFree(function(errn) {
      if (err) throw err;
      console.log('Free bytes for current volume: ' + fmtBytes(n));
  });
  fs.getUsed(function(errn) {
      if (err) throw err;
      console.log('Used bytes for current volume: ' + fmtBytes(n));
  });
 
  // sample output: 
  // 
  // Total bytes for current volume: 974,656,999,424 
  // Free bytes for current volume: 877,061,001,216 
  // Used bytes for current volume: 48,814,333,952 

API

  • fs.getTotal([<String>path,] <Function>callback) - (void) - Retrieves the number of total bytes on the volume where path is located (defaults to path of the module). The callback receives two arguments: an <Error> object in case of error (null otherwise) and a <String> containing the number of bytes.

  • fs.getTotalSync([<String>path]) - <String> - Synchronous version of getTotal().

  • fs.getFree([<String>path,] <Function>callback) - (void) - Retrieves the number of free bytes on the volume where path is located (defaults to path of the module). The callback receives two arguments: an <Error> object in case of error (null otherwise) and a <String> containing the number of bytes.

  • fs.getFreeSync([<String>path]) - <String> - Synchronous version of getFree().

  • fs.getUsed([<String>path,] <Function>callback) - (void) - Retrieves the number of used bytes on the volume where path is located (defaults to path of the module). The callback receives two arguments: an <Error> object in case of error (null otherwise) and a <String> containing the number of bytes.

  • fs.getUsedSync([<String>path]) - <String> - Synchronous version of getUsed().