- App.js
- Const express=require(“express”);
- Const app=express();
- App.set(“view engine”,”ejs”);
- Var contactsList=[
- {
- Id:”1”,
- Name:”Sachin”,
- Contact:”1234567891”,
- },
- {
- Id:”2”,
- Name:”Tendulkar”,
- Contact:”2345678912”,
- },
- ]
- App.get(“/”,(req,res)=>{
- Res.render(“Home”);
- });
- App.get(“/contacts”,(req,res)=>{
- Res.render(“contact”,{contactsList});
- });
- App.listen(3001);
- Home.ejs
- <!DOCTYPE html>
- <html lang=”en”>
- <head>
- <meta charset=”UTF-8”>
- <meta name=”viewport” content=”width=device-width, initial-scale=1.0”>
- <title>Document</title>
- <%- include(‘partials/nav.ejs’)%>
- <style>
- Body{
- Background-color: crimson;
- }
- </style>
- </head>
- <body>
- <h1>THIS IS THE HOME PAGE!!</h1>
- </body>
- </html>
- Nav.ejs
- <!DOCTYPE html>
- <html lang=”en”>
- <head>
- <meta charset=”UTF-8”>
- <meta name=”viewport” content=”width=device-width, initial-scale=1.0”>
- <title>Document</title>
- </head>
- <body>
- <nav>
- <ul>
- <li><a href=”/”>Home</a></li>
- <li><a href=”/contacts”>Contacts</a></li>
- </ul>
- </nav>
- </body>
- </html>
- Contact.ejs
- <html lang=”en”>
- <head>
- <meta charset=”UTF-8”>
- <meta name=”viewport” content=”width=device-width, initial-scale=1.0”>
- <title>Document</title>
- <%- include(‘partials/nav.ejs’)%>
- <style>
- Body,table{
- Background-color: aqua;
- }
- </style>
- </head>
- <body>
- <table border=”1px solid cyan” align=”center”>
- <tr>
- <th>ID</th>
- <th>NAME</th>
- <th>CONTACT</th>
- </tr>
- <%contactsList.forEach((contact)=>{%>
- <tr>
- <td><%= contact.id%></td>
- <td><%= contact.name%></td>
- <td><%= contact.contact%></td>
- </tr>
- <%});%>
- </table>
- </body>
- </html>
[text] k2
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: