ExpressJs Handwritten Notes
ExpressJs Handwritten Notes
ExpressJs Handwritten Notes
Fast , unopionated,
minimalist web
framework for Node.js.
Tell express
that ejs will be the
view Engine/
Template engine
that will be used.
tell express
where
the views
file
is kept.
so, whenever html changes
it doesn't
get precompiled.
creating a
controller
for
practice
html file.
for loop
in html
if statement.
It will
always be true.
passing contact list as
one of our locals.
using method
post since, we have to some
change in the database.
before view show us
we pages.
make a route
in controller.
now it will take you to the
other page. /practice
form Filled
Submit
Action Required
Redirected
home.ejs
<html>
<head>
<title><%=title %></title>
</head>
<body>
<h1>Contact List</h1>
<div>
<ul>
<% for(let i of contact_list) {%>
<li>
<p> <%=i.name%></p>
<p><%= i.type%></p>
</li>
<%}%>
</ul>
</div>
</body>
</html>
th
TTT
to append into
contactList
code
2. added a parser
which is middleware.
home.ejs
<html>
<head>
<title><%=title %></title>
</head>
<body>
<h1>Contact List</h1>
<div>
<ul>
<% for(let i of contact_list) {%>
<li>
<p> <%=i.name%></p>
<p><%= i.type%></p>
</li>
<%}%>
</ul>
</div>
</body>
</html>
Middleware
Middleware functions are functions
that have access to the
request object (req), the response object (res), and the next()
in the application’s request-response cycle.
4.
2.
/assets/css/home.css
why not?
/assets/js/home.js
note:
writing the path
in the following ways.
but
:phone
is creating a
key named value
and take values from a tag.
There was a query
here. <%= i.phone %>
method="GET"
{phone: Arpan}
value for controller to use
-- :phone -- here