最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Nodejs process.stdout.write() to variable - Stack Overflow

programmeradmin3浏览0评论

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);         
});

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);         
});
Share Improve this question edited Jan 27, 2020 at 13:42 Ygg 3,8801 gold badge18 silver badges23 bronze badges asked Jan 27, 2020 at 12:38 OberDulli94OberDulli94 1872 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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 pletes reading

发布评论

评论列表(0)

  1. 暂无评论