Last Updated: February 25, 2016
· 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).


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: