How do I read the contents of a Node.js stream into a string variable?

后端 未结 18 2269
日久生厌
日久生厌 2020-11-29 18:55

I\'m hacking on a Node program that uses smtp-protocol to capture SMTP emails and act on the mail data. The library provides the mail data as a stream, and I don\'t know how

18条回答
  •  旧巷少年郎
    2020-11-29 19:19

    I had more luck using like that :

    let string = '';
    readstream
        .on('data', (buf) => string += buf.toString())
        .on('end', () => console.log(string));
    

    I use node v9.11.1 and the readstream is the response from a http.get callback.

提交回复
热议问题