- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
Node.js - os.endianness() Method
The Node.js os.endianness() method will return a string, that will let us know the endianness of the CPU for which the Node.js binary was compiled.
The word endianness is the order or sequence of bytes of a word of digital data in computer memory. The endianness is primarily expressed as big-endian(BE) or little-endian(LE).
Syntax
Following is the syntax of the Node.js os.endianness() method −
os.endianness()
Parameters
This method does not accept any parameters.
Return value
This method will return a string value that specifies the endianness of the current computer. The string can return either big-endian(BE) or little-endian(LE).
Little-endian(LE) − This is an order in which the "little end" (least significant value in the sequence) will be stored first.
Big-endian(BE) − This is an order in which the "big end" (most significant value in the sequence) will be stored first, at the lowest memory address.
Example
In the following example, we are trying to log the Node.js os.endianness() method to the console for printing the endianness of the current system.
const os = require('os'); const {endianness} = os; console.log(os.endianness());
Output
If we compile and run the above program, the os.endianness() method returns the string value that specifies the endianness of the current computer.
LE
Example
In the example below,
We are performing a switch case.
So the switch will check each case against the output string value of the os.endianness() method until a match is found.
If nothing matches, the default condition will be printed.
const os = require('os'); let end = os.endianness(); switch(end) { case 'LE': console.log("CPU is little endian(LE) format"); break; case 'BE': console.log("CPU is big endian(BE) format"); break; default: colsole.log("Unknown endianness"); }
Output
When we compile and run the above program, the output string value of os.endianness() method will be 'LE'. So the case 'LE' got matched and it got executed.
CPU is little endian(LE) format