Node.JS constant for platform-specific new line?


Question

Is there a constant available in Node.JS for a newline character that is specific to the platform the application is running on?

For example:

  • Windows: \r\n
  • *nix: \n
1
88
6/2/2012 5:33:56 PM

Accepted Answer

Not sure if this is new in the 0.8.x but there is now a constant http://nodejs.org/api/os.html#os_os_eol

var endOfLine = require('os').EOL;
200
12/28/2012 1:22:36 AM

Unfortunately there isn't a constant, but you determine it yourself using:

var nl = (process.platform === 'win32' ? '\r\n' : '\n')

(note this is quite a naive solution)


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon