Implementing Dynamic GET Servers

You will use Node.js webservers to serve dynamic content more often than you’ll use them to serve static content. This content may be dynamic HTML files or snippets, JSON data, or a number of other types of data. To serve a GET request dynamically, you need to implement code in the request handler that dynamically populates the data you want to send back to the client, write it out to the response, and then call end() to finalize the response and flush the Writable stream.

Listing 7.3 shows the basic implementation of a dynamic webserver. In this case, the webserver simply responds with a dynamically generated HTTP file. The example is designed to show the process of sending the headers, building the response, ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.