Summary
In this chapter, I described the API features that Node.js provides to read and write data, particularly when processing an HTTP request:
- Streams are used as abstract representations of sources and destinations for data, including HTTP requests and responses.
- Data is buffered when it is written to a stream, but it is a good idea to avoid excessive buffering because it can exhaust system resources.
- Data can be read from a stream by handling events or using a
for
loop. - Data can be piped from a readable stream to a writable stream.
- Data can be transformed as it is piped and can be between JavaScript objects and strings/byte arrays.
- Node.js provides an API to work with files, but third-party packages are the safest way to work with files in a web server project.
- Third-party packages, such as Express, provide enhancements to the Node.js streams to perform common tasks, such as decoding JSON data.
In the next chapter, I describe...