Last Updated: February 25, 2016
·
7.16K
· deleteman

Split lines cross-platform in Node.js

Sometimes, splitting lines by "\n" is not enough, there is a very little known but useful constant lying around the OS module that'll help us on this task: EOL (which contains the correct end of line character for each OS).

Example:

var os = require("os");

var text = "...."; //Big text with many line breaks
text.split(os.EOL); //Will return an array of lines on every OS node works on

More details: http://nodejs.org/api/os.html