npm install os-name

Get the name of the current operating system. Example: macOS Sierra

About os-name

The npm package "os-name" is an essential tool for developers needing to retrieve the name of the current operating system on which their node.js application is running. This package supports a wide range of operating systems, providing accurate identification from common systems like Windows, macOS, and various distributions of Linux. The ability to detect the operating system is particularly useful for applications that perform OS-specific operations or optimizations, enhancing the user experience by tailoring functionality to the user's environment. Additionally, "os-name" is invaluable for collecting analytics and aiding in debugging by allowing developers to easily log and understand the environments where their applications are deployed.

To incorporate "os-name" into a project, developers can simply run "npm install os-name" to add it to their node.js applications. Once installed, it can be easily integrated into any part of the application where knowing the operating system could influence behavior or output. The simplicity of using "os-name" lies in its straightforward API, which returns the operating system name in a human-readable string, such as "macOS Sierra" or "Windows 10". This feature is particularly advantageous for developers working in diverse development environments or those managing applications across different operating systems. The "os-name" package ensures that applications can adapt seamlessly to the OS-specific features and requirements, making it a staple in modern software development toolkits.

More from sindresorhus

sindresorhus npm packages

Find the best node modules for your project.

Search npm

path-key

Get the PATH environment variable key...

Read more
,

slash

Convert Windows backslash paths to slash...

Read more
,

is-wsl

Check if the process is running inside Windows Subsystem for Linux (Bash on...

Read more
,

log-symbols

Colored symbols for various log levels...

Read more
,

default-browser-id

Get the bundle identifier of the default browser (macOS). Example: com.apple...

Read more
,

run-applescript

Run AppleScript and get the...

Read more
,

default-browser

Get the default...

Read more
,

bundle-name

Get bundle name from a bundle identifier (macOS): `com.apple...

Read more
,

os-name

Get the name of the current operating system...

Read more
,

windows-release

Get the name of a Windows version from the release number: `5.1...

Read more
,

macos-release

Get the name and version of a macOS release from the Darwin...

Read more

Dependencies

Core dependencies of this npm package and its dev dependencies.

macos-release, windows-release, @types/node, ava, tsd, xo

Documentation

A README file for the os-name code repository. View Code

os-name

Get the name of the current operating system
Example: macOS Sierra

Useful for analytics and debugging.

Install

npm install os-name

Usage

import os from 'node:os';
import osName from 'os-name';

// On a macOS Sierra system

osName();
//=> 'macOS Sierra'

osName(os.platform(), os.release());
//=> 'macOS Sierra'

osName('darwin', '14.0.0');
//=> 'OS X Yosemite'

osName('linux', '3.13.0-24-generic');
//=> 'Linux 3.13'

osName('win32', '6.3.9600');
//=> 'Windows 8.1'

API

osName(platform?, release?)

By default, the name of the current operating system is returned.

You can optionally supply a custom os.platform() and os.release().

Check out getos if you need the Linux distribution name.

Related