JavaScript Node.js Array to text with newline node.js array to text file,node red dashboard text

I wanted to convert an array to a textfile with a newline separating each entry.

I found out about an npm package called array-to-txt-file. Here is the webpage: array-to-txt-file

This package claims that will concatenate every element of the array with a newline, so that every element of the array appears on its own line on the text file.

So i gave it a try and while it works great it doesn't concatenate the elements with a newline. Where one element ends, another one begins.

So i took a look at the source code of the package and this is the code that creates this effect.

try {
    array.forEach(v => {
      if(_.isPlainObject(v)) {
        ws.write(`${JSON.stringify(v)}\n`)
        return
      }
      ws.write(`${v}\n`)
    })

Especially the ws.write(${v}\n) part.

I then imported my output text file into a hex editor. In the hex editor there was dot between each element. Now, this dot was different to a regular dot.

While a regular dot has the hex value of 2E, the dot that appears between the elements has 0A. Please also note that i am using Windows 7, and when viewed with notepad, nothing appears between the elements - where one ends, another one begins straight up.

So is there a way to modify that line in the code i posted above, so it really creates a newline in that part?

Answer:1

On Linux, \n represents new line.

Two characters combined \r\n represent a new line on Windows.

Try replacing \n with \r\n in both the write statements inside index.js file of the module.

Those dots represent non-printable characters. While the regular dot . FULL STOP (U+002E) is represented by 2E.

More information: https://en.wikipedia.org/wiki/Newline

Answer:2

I've read that having an async inside a Promise is anti-pattern for async/await. The code below works, but I am curious how else to achieve the same result without having async in Promise. If I ...

I've read that having an async inside a Promise is anti-pattern for async/await. The code below works, but I am curious how else to achieve the same result without having async in Promise. If I ...

I have a m("p.help") element which is removed with a click event. I also want the element to be removed automatically after a few seconds if not clicked. I need to set a time out on it. Setting time ...

I have a m("p.help") element which is removed with a click event. I also want the element to be removed automatically after a few seconds if not clicked. I need to set a time out on it. Setting time ...

This is the result: This is what the page shows when the JSON sets childnode.state.selected For example: {"children":[],"id":37,"text":"应用显 示","orderid":1,"parent":36,"state":{"disabled":false,"...

This is the result: This is what the page shows when the JSON sets childnode.state.selected For example: {"children":[],"id":37,"text":"应用显 示","orderid":1,"parent":36,"state":{"disabled":false,"...

I have a container that is a certain width. I have two select elements rendering on the same line in this main div container. The first one is absolute positioned 40px left from the main div ...

I have a container that is a certain width. I have two select elements rendering on the same line in this main div container. The first one is absolute positioned 40px left from the main div ...