[text] k2

Viewer

  1. App.js
  2. Const express=require(“express”);
  3. Const app=express();
  4. App.set(“view engine”,”ejs”);
  5. Var contactsList=[
  6.  {
  7.  Id:”1”,
  8.  Name:”Sachin”,
  9.  Contact:”1234567891”,
  10.  },
  11.  {
  12.  Id:”2”,
  13.  Name:”Tendulkar”,
  14.  Contact:”2345678912”,
  15.  },
  16. ]
  17. App.get(“/”,(req,res)=>{
  18.  Res.render(“Home”);
  19. });
  20. App.get(“/contacts”,(req,res)=>{
  21.  Res.render(“contact”,{contactsList});
  22. });
  23. App.listen(3001);
  24. Home.ejs
  25. <!DOCTYPE html>
  26. <html lang=”en”>
  27. <head>
  28.  <meta charset=”UTF-8”>
  29.  <meta name=”viewport” content=”width=device-width, initial-scale=1.0”>
  30.  <title>Document</title>
  31.  <%- include(‘partials/nav.ejs’)%>
  32.  <style>
  33.  Body{
  34.  Background-color: crimson; 
  35.  }
  36.  </style>
  37. </head>
  38. <body>
  39.  <h1>THIS IS THE HOME PAGE!!</h1>
  40. </body>
  41. </html>
  42. Nav.ejs
  43. <!DOCTYPE html>
  44. <html lang=”en”>
  45. <head>
  46.  <meta charset=”UTF-8”>
  47.  <meta name=”viewport” content=”width=device-width, initial-scale=1.0”>
  48.  <title>Document</title>
  49. </head>
  50. <body>
  51.  <nav>
  52.  <ul>
  53.  <li><a href=”/”>Home</a></li>
  54.  <li><a href=”/contacts”>Contacts</a></li>
  55.  </ul>
  56.  </nav>
  57. </body>
  58. </html>
  59. Contact.ejs
  60. <html lang=”en”>
  61. <head>
  62.  <meta charset=”UTF-8”>
  63.  <meta name=”viewport” content=”width=device-width, initial-scale=1.0”>
  64.  <title>Document</title>
  65.  <%- include(‘partials/nav.ejs’)%>
  66.  <style>
  67.  Body,table{
  68.  Background-color: aqua;
  69.  }
  70.  </style>
  71. </head>
  72. <body>
  73.  <table border=”1px solid cyan” align=”center”>
  74.  <tr>
  75.  <th>ID</th>
  76.  <th>NAME</th>
  77.  <th>CONTACT</th>
  78.  </tr>
  79.  <%contactsList.forEach((contact)=>{%>
  80.  <tr>
  81.  <td><%= contact.id%></td>
  82.  <td><%= contact.name%></td>
  83.  <td><%= contact.contact%></td>
  84.  </tr>
  85.  <%});%>
  86.  </table>
  87. </body>
  88. </html>

Editor

You can edit this paste and save as new:


File Description
  • k2
  • Paste Code
  • 02 May-2024
  • 1.72 Kb
You can Share it: