Express
Express
app.use([path,] callback)
What it does: It's a method to define middleware functions in Express.
Parameters:
path: Optional. It's the specific route the middleware should run (e.g.,
/middleware). If omitted, it applies to all routes.
callback: A function that is mandatory and runs every time a request
hits the server.
Understanding Request and Response Objects (req and res)
Both req (request) and res (response) are objects.
Whenever a client sends a request, the server stores that request as a req
object.
Similarly, when the server sends a response, it stores it as a res object.
You can log these objects to inspect the incoming request and outgoing
response.
Sending a Response with res.send()
The res.send() method sends a response back to the client.
Mental Model
res.render(view [, locals] [, callback])
Express uses res.render() to display views.
view: the template to be rendered.
what is view?
view is a template/ strucuture .
and template ko krna hota hai show
and show krne ke liye mujhe eak engine ki zarurat padegi (browser engines)
we have different templating engines to show template.
Templating Engines
Engines like EJS, Handlebars, Jade/Pug.
all these are my templating engines and this will help me to show the template
on browser.
But we will use ejs templating engine.