Languages
[Edit]
EN

Node.js - split string by new line character (JavaScript)

4 points
Created by:
Fletcher-Peralta
778

In this article, we're going to have a look at the problem of how to split string to separate lines in Node.js.

Example JavaScript source code run under Windows:

Output:

Note: depending on operating system we have different END OF LINE symbols.

 

In practice, applications exchange data with external environment - it forces programmer to take care of the different cases.

If we are looking for some simple universal solution we can use:

Hint: check this article to know more universal solutions.

 

Other solutions

Edit

There is available some npm package to deal with newline characters.

Links:

  1. EOL - npm page
  2. EOL - GitHub page

Package installation: 

Usage example:

 

See also

Edit
  1. JavaScript - split string by new line character

Alternative titles

  1. Node.js - split string by newline character (JavaScript)
  2. Node.js - split text by new line character (JavaScript)
  3. Node.js - split text by newline character (JavaScript)
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join