response.renderfunction to produce an HTML string with the given template and data to return to the client.
viewsfolder and store our EJS templates in it.
response.renderto render an HTML response to the client,
renderwill tell EJS which EJS template to use and pass relevant data to inject into that template.
index.js, set EJS as the Express template engine to generate HTML responses. Insert the following line below where we initialise
appand above any routes.
response.renderwith the following 2 params.
fruit.ejsis a sample EJS template for this example. EJS templates look like HTML files, except with "templating syntax" to inject JS variables into the HTML. In this example, we inject the properties of the
fruit.ejs. Templating concepts and syntax are similar across most web application frameworks, including Ruby on Rails, Python Django, and Java Spring.
fruit.ejs. There are few exceptions to this convention.
.prettierignorefile at the root of the folder open in VSCode to ignore files with a
.prettierignorefile at the root of the folder open in VSCode with the following contents. For example, if my
rocketfolder is open in VSCode with many subfolders such as
projects, I will add
rocketfolder and not any of its subfolders. More info on Prettier Ignore here.
.prettierignorefor Prettier to format the HTML in our EJS templates.
fruit.ejsand fill it with another attribute in the
/fruits/:name. Inject the path param value in the response HTML by adding the param to the
dataobject, then referencing it in the EJS template.