Skip to content

Commit

Permalink
applying for Each loop on array list
Browse files Browse the repository at this point in the history
  • Loading branch information
codingXpert committed Jul 2, 2022
1 parent 94b9dd4 commit 2af19d4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
32 changes: 32 additions & 0 deletions index2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const express = require('express');


const port = 8000;
const app = express();

//Telling Node Js that ue are using view engine of ejs
app.set('view engine' , 'ejs');

app.get('/' , (req , res) => {
res.render('home');
})

app.get('/profile' , (req , res) => {
user = {
name:'Anil',
email:'[email protected]',
city:'Noida',
skills:['HTML' , 'Css' , 'Js' , 'Node Js' , 'Java']
}
res.render('profile' , {user});
});


app.listen(port , (err) => {
if(!err){
console.log(`Server is running on the port::${port}`);
}
});



27 changes: 19 additions & 8 deletions views/profile.ejs
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Profile page</title>
</head>
<body>
</head>
<body>

<h1>Profile Page</h1>
<h3>Welcome <%= user.name %></h3>
<h3>Email:<%= user.email %></h3>
<h3>City:<%= user.city %></h3>
</body>
</html>
<h3>Skills:<%= user.skills %></h3>

<!-- Appliying forEach loop on skills -->
<ul>
<% user.skills.forEach((item) => { %>
<li><%= item %></li>
<% }) %>
</ul>

</body>
</html>

0 comments on commit 2af19d4

Please sign in to comment.