We touched on the manipulation of views in the Routers section, so let's now dive in deeper. The view layer of an application is the presentation layer, which is why it houses our frontend JavaScript. While not all backend Node applications will serve a frontend, it's handy to know how to use it. Whenever I set up a simple webserver, I reach for Express and its functionality for both the frontend and backend.
Since there are multiple frontend templating languages available to us, let's use Handlebars as an example of logic and structure.
If we want to, we can provide some conditional logic in our frontend code. Note that this logic is rendered by the backend, so it's a good example of when to render data on the backend (which is more performant for the frontend) and when to do it via JavaScript (which is, ostensibly, more flexible).
Let's alter our views/index.hbs file like this:
{{#if data }}
<p id="data">{{ data }}</p>
{...