Giter VIP home page Giter VIP logo

node-df's Introduction

df

Build Status

node-df (abbreviation of disk free) is a cross-platform Node.js wrapper around the standard Unix computer program, df.

Installation

$ npm install node-df

Usage

Basic

var
    df = require('node-df');

df(function (error, response) {
    if (error) { throw error; }

    console.log(JSON.stringify(response, null, 2));
});

Output from df looks like this:

[
  {
    "filesystem": "/dev/disk0s2",
    "size": 487546976,
    "used": 164493356,
    "available": 322797620,
    "capacity": 0.34,
    "mount": "/"
  },
  {
    "filesystem": "devfs",
    "size": 186,
    "used": 186,
    "available": 0,
    "capacity": 1,
    "mount": "/dev"
  },
  {
    "filesystem": "map -hosts",
    "size": 0,
    "used": 0,
    "available": 0,
    "capacity": 1,
    "mount": "/net"
  },
  {
    "filesystem": "map auto_home",
    "size": 0,
    "used": 0,
    "available": 0,
    "capacity": 1,
    "mount": "/home"
  },
  {
    "filesystem": "localhost:/CPYpGwk1x_UGJYGx-93flp",
    "size": 487546976,
    "used": 487546976,
    "available": 0,
    "capacity": 1,
    "mount": "/Volumes/MobileBackups"
  }
]

Values for size, used and available are expressed in KiB (1024 bytes).

Value for capacity is a number between 0 and 1. capacity is also known as used%

node-df correctly parsed output from df unix program for filesystems and mount folders with whitespaces in the name.

Advanced

var
    options = {
        file: '/',
        prefixMultiplier: 'GB',
        isDisplayPrefixMultiplier: true,
        precision: 2
    };

df(options, function (error, response) {
    if (error) { throw error; }

    console.log(JSON.stringify(response, null, 2));
});

Output from df now looks like this:

[
  {
    "filesystem": "/dev/disk0s2",
    "size": "499.25GB",
    "used": "168.44GB",
    "available": "330.54GB",
    "capacity": 0.34,
    "mount": "/"
  }
]

Options

  • file: output the amount of free space of the file system containing the specified file;
  • prefixMultiplier: convert size, used and available values from KiB to MiB, GiB, PiB, EiB, ZiB, YiB, MB, GB, PB, EB, ZB, YB;
  • isDisplayPrefixMultiplier: if true, values for size, used and available are converted to strings and prefixMultiplier is displayed (see example above).
  • precision: round size, used and available values to precision decimal digits.

node-df's People

Contributors

adriano-di-giovanni avatar huntr-helper avatar mufeedvh avatar

Watchers

 avatar

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.