Node js os.machine() Method
Last Updated :
12 Sep, 2023
The os.machine method is an inbuilt application programming interface of the os module which is used to get the machine type. The os package contains the required function to perform operating system operations.
Syntax:
os.machine()
Parameters: This function does not have any parameters.
Return Value: This function returns the machine type in the string type. Returns the machine type as a string, such as arm, arm64, aarch64, mips, mips64, ppc64, ppc64le, s390, s390x, i386, i686, x86_64.
Example 1: The below example illustrates the os.machine() method in Node js.
Note: The output may be different according to your computer operating system.
Javascript
const os = require( 'os' );
console.log(os.machine());
|
Output:
x86_64
Example 2: The below example illustrates the os.machine() method in Node js
Javascript
const os = require( 'os' );
const platform = os.machine();
switch (platform) {
case 'arm' : console.log( "arm machine type" );
break ;
case 'arm64' : console.log( "ARM CPU architecture" );
break ;
case 'x86_64' : console.log( "64-bit processing" );
break ;
default : console.log( "unknown platform" );
}
|
Output:
64-bit processing
Note: The above program will compile and run by using the node index.js command.
Reference: https://nodejs.org/api/os.html#osmachine
Share your thoughts in the comments
Please Login to comment...