Using third-party enhancements
In the sections that follow, I describe useful enhancements provided by the Express package to deal with streams and tasks that are related to HTTP. Express isn’t the only package that provides these kinds of features, but it is a good default choice for new projects and gives you a foundation from which to compare alternatives.
Working with files
One of the most important tasks for a web server is to respond to requests for files, which provide browsers with the HTML, JavaScript, and other static content required by the client-side part of the application.
Node.js provides a comprehensive API to deal with files in the fs
module, and it has support for reading and writing streams, along with convenience features that read or write complete files, such as the readFileSync
function I used to read the contents of an HTML file.
The reason I have not described the API in any detail is that working directly with files within a web...