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
Written by Fernando Doglio
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Nodejs
Authors
Related Tags
#nodejs
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#