What is getos?
The getos npm package is used to detect the operating system of the environment in which a Node.js application is running. It provides a simple API to retrieve detailed information about the OS, including the distribution name and version for Linux systems.
What are getos's main functionalities?
Detect Operating System
This feature allows you to detect the operating system of the environment. The callback function returns an object containing details about the OS, such as the distribution name and version for Linux systems.
const getos = require('getos');
getos((e, os) => {
if (e) return console.log(e);
console.log(os);
});
Detect Linux Distribution
This feature is specifically useful for detecting the Linux distribution and its version. The callback function checks if the OS is Linux and then logs the distribution name and version.
const getos = require('getos');
getos((e, os) => {
if (e) return console.log(e);
if (os.os === 'linux') {
console.log(`You are running ${os.dist} version ${os.release}`);
}
});
Other packages similar to getos
os
The 'os' module is a built-in Node.js module that provides operating system-related utility methods and properties. Unlike getos, it does not provide detailed information about Linux distributions but offers a broader range of OS-related functionalities.
systeminformation
The 'systeminformation' package provides detailed system and hardware information. It offers more comprehensive data compared to getos, including CPU, memory, and network details, but may be overkill if you only need OS detection.
node-os-utils
The 'node-os-utils' package provides a set of utilities to get information about the operating system, including CPU, memory, and disk usage. It offers more extensive system monitoring capabilities compared to getos.
GETOS
A simple npm utility to supplement os.platform()
Problem
os.platform()
returns linux
. If you want the distrubtion name, you are S.O.L.
Solution
This. Simply call
var getos = require('getos')
getos(function(e,os) {
if(e) return console.log(e)
console.log("Your OS is:" +JSON.stringify(os))
})
The os
object conforms to:
{
"dist":[DIST NAME]
"codename":[CODENAME]
"release":[VERSION]
}
Disclaimer
Check os.json
in this repo. Any distribution that shares a common resource file with another distrubtion is currently untested. These are the arrays of distrubitons with more than 1 member. If you are using one of these distrubtions, please submit an issue letting me know if it works. If it fails, please post the content of the file.
If you have a distrubtion not in os.json
, please identify your resource file and submit it's name and content along with your distrbution/version in an issue.
Thanks for helping make this tool great.
TESTS
The tests currently offer only visual confirmation of the output (since we don't really have a specification we conform to).
The tests are powered by docker, and must be run from the top level directory of the project. You can run them via
node tests/runTest.js
They are powered by docker, so you must have docker installed to run the tests. You will notice that the first time the tests run, they will probably take somewhere between 30 minutes and 4 hours to complete. They download a bakers dozen of gigs to build the docker images. Pretty network intensive stuff. Also, if you are a neckbeard and have your HDD partitioned to isolate /var and /tmp on small partions, the tests will probably crash. /tmp will need ~4GB of free space for the tests to run. /var will need ~20GB to store all the images.
You can also run the tests via
npm test
But the fantastic spinner packaged with npm mucks up stdout, so output will be garbaled.