Posts

Showing posts from November, 2022

Query Parameters vs Route Parameters

 Route Parameters in "Dynamic Routes" In this section, you learned about "dynamic routes" that utilize route parameters to extract dynamic values from the URL path. For example: router.get('/restaurants/:id', ...) In this example, id is a route parameter that will hold different values when this URL / path is visited. For example, if a user enters /restaurants/r1, id will be equal to r1. Route parameters are super useful as they allow us to use one single route to load different data based on the concrete route parameter value. It is important to understand that the route parameter (:id in the above example) is a key part of the URL path. Just /restaurants would NOT be handled by the above route for example - because it's missing a value for the route parameter. Query Parameters We also learned about a concept called "query parameters" in this section. It's easy to mix up "query parameters" and "route parameters" but the...

EJS

Image
 EJS (Embedded JavaScript Templating) is one of the most popular template engines for JavaScript. As the name suggests, it lets us embed JavaScript code in a template language that is then used to generate HTML. In this article, I will walk you through a detailed guide to templating your Node application with EJS. First, we’ll cover the basics of template engines and setting up EJS, but we will move on to a more advanced guide to using EJS in your Node apps. Template engines According to Wikipedia’s definition, a template engine is a software designed to combine templates with a data model to produce, in our case, real HTML code.