Ad

Writing Vars To A Csv File In Node.js

- 1 answer

I would like to write the data inside of a var to a csv file using node. I saw a youtube video writing await fs.appendFile('out.csv','${userName}, ${email}'). But this writes "userName" into the csv, instead of the contents inside this var.

console Logging the userName and email vars show the correct info. Could someone tell me how this fs function works?

Ad

Answer

the problem is not related to fs it's because you are using single quotes instead of backticks, use ES6 template literals to substitute variables into string.

Ad
source: stackoverflow.com
Ad