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:
const os = require( 'os' );
console.log(JSON.stringify(os.EOL));
|
Output:
"\r\n"
Example 2:
const os = require( 'os' );
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);
|
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
Last Updated :
13 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...