2

I got a quick question. I want to save the value (string) of this statement:

process.stdout.write(d); 

in a variable. But all my attempts failed so how is it done?

res.on('data', (d) => {
    process.stdout.write(d);         
});

1 Answer 1

7

You can do it like this

var str = "";

res.on('data', (d) => {
   str+=d;
}).on('end',()=>{
   console.log(str);
});

Here we append the data d we get from stream, we append it to str variable & the print the str once the stream completes reading

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.