Creating an HTTP server
When building large complex applications, it is typical to implement HTTP servers using a higher-level web framework rather than interacting with core Node.js APIs. However, understanding the underlying APIs is important, and in some cases, only interacting with the underlying Node.js APIs will provide you with the fine-grained control required in certain circumstances.
In the previous section, we explored foundational concepts of HTTP and relevant Node.js core APIs. In this tutorial, we’ll guide you through the process of building an HTTP server using Node.js where we’ll initially focus on handling GET
requests – fundamental functionality for web servers.
Getting ready
Start by creating a directory for this recipe and a file named server.js
that will contain our HTTP server:
$ mkdir http-server $ cd http-server $ touch server.js
How to do it…
For this recipe, we will be using the core Node.js http
module. API documentation...