0

This is the code

$('.Text').each(function() {
            var data = $(this);
            temp = data.text();
            
            fs.appendFile('output.csv',  temp , function(err) {
                if (err)
                    console.log(err);
            });
});

In first three iterations temp is

"I am komal" "Nice to meet u" "ok?"

But it comes as a single line

"I am komal""Nice to meet u""ok?"

I want each of them to be a row in a single column

user3423235
  • 65
  • 3
  • 9
  • Where are you running this code? Server or Browser? Please give some more context. What are you trying to achieve? – Brasilikum Jun 09 '15 at 06:21

2 Answers2

0

Adding a carriage return should add move you to next line.

$('.Text').each(function() {
            var data = $(this);
            temp = data.text() + String.fromCharCode(13);

            fs.appendFile('output.csv',  temp , function(err) {
                if (err)
                    console.log(err);
            });
});

Link to similar query.

Community
  • 1
  • 1
Gaurav Gupta
  • 4,586
  • 4
  • 39
  • 72
0

fs.appendFile doesn't automatically add newline characters to the content you pass it - you need to do that yourself:

        fs.appendFile('output.csv',  temp +"\n", function(err) {
            if (err)
                console.log(err);
        });
knolleary
  • 9,777
  • 2
  • 28
  • 35