Câu hỏi phỏng vấn Nodejs
Câu hỏi

What is stream and what are types of streams available in Node.js?

Câu trả lời

Streams in Node.js are abstract interfaces for working with streaming data. They are designed to handle reading and writing data in a continuous fashion, which is particularly useful for dealing with large amounts of data that might not fit into memory if handled all at once. Streams allow data to be processed piece by piece, or in chunks, which can lead to more efficient memory usage and faster processing times.

There are four primary types of streams in Node.js:

  1. Readable Streams: These are streams from which data can be read. They allow you to receive data from a source, such as a file or a network request, and process it sequentially. Examples include reading data from a file using fs.createReadStream() or receiving a request in an HTTP server.

  2. Writable Streams: These streams allow you to send data to a destination. You can write data to a file, send data over a network, or process.stdout, which is used for writing output to the console. An example is writing data to a file using fs.createWriteStream().

  3. Duplex Streams: Duplex streams are both readable and writable. They can be used to read from and write to a medium, such as a TCP socket, allowing for two-way communication.

  4. Transform Streams: These are a type of duplex stream that can modify o...

middle

middle

Gợi ý câu hỏi phỏng vấn

middle

Is there any difference between res.send and return res.send in Express.js?

senior

When not to use Node.js?

expert

Why do we need C++ Addons in Node.js?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào