Node.JS constant for platform-specific new line?

前端 未结 2 491
南方客
南方客 2020-12-07 19:32

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:
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 20:26

    Node.js 0.6.x and earlier:

    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)

提交回复
热议问题