OS Utils
The `os-utils` package is a Node.js library offering fundamental operating system utility functions. It enables developers to retrieve basic system metrics such as CPU usage (calculated per second, not as an average), total and free memory, platform identification, and system/process uptime. The package's latest version, 0.0.14, was released on October 30, 2012, signifying that its development has ceased and it is no longer actively maintained. Its release cadence was effectively non-existent after this initial publication. Compared to contemporary system monitoring libraries like `node-os-utils` or `systeminformation`, `os-utils` provides a very limited, callback-based API, lacks modern features such as TypeScript support, sophisticated error handling, or intelligent caching mechanisms, making it unsuitable for modern Node.js applications or environments requiring robust system insights.
Common errors
-
ERR_REQUIRE_ESM: require() of ES Module ... not supported. Instead change the require of ... to a dynamic import()
cause Attempting to use `require('os-utils')` within an ECMAScript Module (ESM) file or project configured as 'type': 'module' in `package.json`.fixEnsure your file is a CommonJS module (e.g., ends with `.cjs` or `package.json` specifies `'type': 'commonjs'`) or refactor your project to use an ESM-compatible system monitoring library. You *cannot* `import` this package directly as it's pure CommonJS. -
TypeError: os.cpuUsage is not a function
cause Incorrectly trying to destructure the module or using an import syntax that results in `os` not being the module object, or the `os-utils` package wasn't installed correctly.fixAlways import `os-utils` using `const os = require('os-utils');` and access its methods as `os.methodName()`. Verify `npm install os-utils` completed successfully.
Warnings
- breaking The `os-utils` package is completely unmaintained, with its last update over a decade ago (version 0.0.14 published in October 2012). It is highly likely to have compatibility issues with modern Node.js versions and environments.
- gotcha The package uses a callback-based API, which is an outdated pattern in modern asynchronous JavaScript. Integrating it into Promise-based or async/await codebases requires manual promisification or wrapper functions.
- gotcha The `cpuUsage` and `cpuFree` functions calculate CPU usage for 'the next second' and are not true averages like those provided by Node.js's native `os` module or other monitoring tools. This can lead to misleading or inconsistent metrics.
- breaking Being an unmaintained package, `os-utils` may contain unpatched security vulnerabilities. Directly interacting with operating system APIs through outdated code poses a significant supply chain risk.
Install
-
npm install os-utils -
yarn add os-utils -
pnpm add os-utils
Imports
- module object
import os from 'os-utils';
const os = require('os-utils'); - cpuUsage
import { cpuUsage } from 'os-utils';const os = require('os-utils'); os.cpuUsage(function(v) { /* ... */ }); - freememPercentage
import { freememPercentage } from 'os-utils';const os = require('os-utils'); os.freememPercentage();
Quickstart
const os = require('os-utils');
// Get CPU usage for the next second
os.cpuUsage(function(v) {
console.log('CPU Usage (%): ' + v);
});
// Get free CPU for the next second
os.cpuFree(function(v) {
console.log('CPU Free (%): ' + v);
});
// Get platform name
console.log('Platform:', os.platform());
// Get number of CPUs
console.log('CPU Count:', os.cpuCount());
// Get current free memory in MB
console.log('Free Memory (MB):', os.freemem());
// Get total memory in MB
console.log('Total Memory (MB):', os.totalmem());
// Get free memory percentage
console.log('Free Memory Percentage (%):', os.freememPercentage());