141

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
2
  • 2
    Why not simply use \n all the time? Jun 2, 2012 at 17:36
  • 9
    @ThiefMaster, ... because I would like files written to line up with the standards for the platform in use.
    – Brad
    Jun 2, 2012 at 17:37

1 Answer 1

287

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

const {EOL} = require('os');
4
  • 1
    new in : v0.7.8, use with care Aug 11, 2017 at 10:25
  • 18
    or const { EOL } = require('os');
    – undefined
    Oct 7, 2019 at 22:37
  • I amended to yours which is more modern @Not loved
    – Will Munn
    Feb 2, 2021 at 22:25
  • 3
    These days, you can even get away with import { EOL } from 'os', but I also recognize the answer was written in 2012 with comments/edits going to 2019
    – DDPWNAGE
    Jul 28, 2022 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.