Node.js | os.EOL

The os.EOL constant is an inbuilt application programming interface of the os module which is used to get end-of-line character or marker as specified by the operating system.

Syntax:

os.EOL

Return Value: It returns the EOL (end-of-line marker) as specified by the operating system on which it is running.



Below examples illustrate the use of os.EOL constant in Node.js:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the   
// os.EOL constants
  
// Allocating os module
const os = require('os');
  
// Printing os.EOL character(s) by
// stringifying to JSON otherwise it
// will simply print as end of line
console.log(JSON.stringify(os.EOL));

chevron_right


Output:

"\r\n"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the   
// os.EOL constants
  
// Allocating os module
const os = require('os');
  
// Printing os.EOL character(s) with string
console.log("Paragraphs always contains EOL"
        + os.EOL + "EOL stands for end of line");
  
console.log("EOL varies from os to os" + os.EOL
            + "For windows it is \\r\\n" + os.EOL
            + "For POSIX it is \\n" + os.EOL);

chevron_right


Output:

Paragraphs always contains EOL
EOL stands for end of line
EOL varies from os to os
For windows it is \r\n
For POSIX it is \n

Note: The above program will compile and run by using the node index.js command.

Reference: https://nodejs.org/api/os.html#os_os_eol



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.