Node.js: do not reinvent the wheel by serving static files from scratch

In Node.js serving static files from scratch is quite a long and complex task.

Unlike traditional web servers, Node doesn't know in advance how to handle static files. You have to use the fs module to get the requested file from the filesystem, read its contents and output such contents in the correct way.
For text files, such as HTML, CSS and JS files, the output will be a string while it will be a stream of bytes for binary files such as images.

Bear in mind that the fs module doesn't provide an utility for getting the content type of a file. The current alternative is to include a third-party module, provided that such module relies on a safer approach than simply
getting the file extension for determining the MIME type to use.

Note how HTML files are converted to strings before they are pushed to the output stream. Instead, our image has been served as a binary stream by using the correct parameter in the end() method. It should be clear now that handling manually
a web server with Node is quite a complex and verbose task to accomplish. That's why we normally use an application framework such as ExpressJS.