@queeniris
Day 94 of #100DaysOfCode – First Steps with EJS & Dynamic Templating
Today, I started working with EJS (Embedded JavaScript Templates) in Node.js, and it’s already clear how powerful it is for building dynamic web pages.
I created a simple Express server that checks whether the current day is a weekday or weekend, and then displays a matching message on the page using an EJS template.
Here’s a part of what I worked on:
import express from "express";
const app = express();
const port = 3000;
app.get("/", (req, res) => {
const today = new Date();
const day = today.getDay();
let type = "a weekday";
let adv = "it's time to work hard";
if (day === 0 || day === 6) {
type = "the weekend";
adv = "it's time to have some fun";
}
res.render("solution.ejs", {
dayType: type,
advice: adv,
});
});
app.listen(port, () => {
console.log(`Server running on port ${port}.`);
});