bjskistad bjskistad - 16 days ago 4x
Node.js Question

How to read file with \n character in it?

I read that you can read a file line by line in Node.js like this:

var array = require("fs").readFileSync("file").toString().split("\n");

But, if the file has a
character in it, it splits that too, so you don't get the file lines the right way.

Is there a way I can read a file with
characters and get the files lines correctly?

For example, how would I split this file?

print "\n"

When I run the above code, it results like this:

[ 'file', 'print "\\n"', 'exec' ]



From comment above but it's the same as before ...

var array = require("fs").readFileSync("file").toString().split(String.fromCharCode(10));