- 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.EOL Property
The Node.js os.EOL property stands for operating system-specific end-of-line marker. This is used to get the end-of-line marker or character as specified by the operating system.
If we try to run the os.EOL on the windows operating system will return "\r\n" to the output. Else if we run it on POSIX operating system, it will return "\n" to the output.
Syntax
Following is the syntax of the Node.js os.EOL property −
os.EOL
Parameters
The os.EOL does not accept any parameters.
Return value
It returns the EOL (end-of-line marker) which is specified by the operating system.
Now let's dive into the examples of the os.EOL of Node.js in different scenarios.
Example
In the following example, we are trying to print the os.EOL property by using JSON.stringify. If we try to print without stringifying it, it will print as the end of line.
const os = require('os'); const { EOL } = os; console.log(JSON.stringify((os.EOL)));
Output
"\n"
Note − To get the accurate result, better execute the above code in local.
If we compile and run the above program, os.EOL prints as shown in the below figure.
"\r\n"
Example
In the example below, we are printing the os.EOL along with a string. So, it will behave similarly to a 'new line'.
const os = require('os'); const { EOL } = os; console.log('Welcome to Tutorialspoint' + os.EOL + 'Hope you have a great learning here!');
Output
As we can see in the output figure below, the string before the os.EOL printed and then os.EOL printed end-of-line, so the string after the os.EOL will print in a new line below.
Welcome to Tutorialspoint Hope you have a great learning here!
Example
In the following example, we are printing the os.EOL character(s) along with a set of strings.
const os = require('os'); const { EOL } = os; console.log('The calender months are' + os.EOL + "JANUARY" + os.EOL + "FEBRAURY" + os.EOL + "MARCH" + os.EOL + "APRIL" + os.EOL + "MAY" + os.EOL + "JUNE" + os.EOL + "JULY" + os.EOL + "AUGUST" + os.EOL + "SEPTEMBER" + os.EOL + "OCTOBER" + os.EOL + "NOVEMBER" + os.EOL + "DECEMBER");
Output
If we compile and run the above program, a set of strings will be printed along with os.EOL. The os.EOL prints the end-of-line so the next string after every os.EOL will be printed in the next line.
The calender months are JANUARY FEBRAURY MARCHAPRIL MAY JUNE JULY AUGUST SEPTEMBER OCTOBER NOVEMBER DECEMBER