Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why Ejs not being recognized by vscode

I have searching for solutions but nothing working. I installed ejs extention on vs code and also dependency. added *ejs and html in setting and tried several solution on StackOverFlow. The answer should come as Its a Weekend or Weekday but <%KindOfDay%> EJS not working.

/view/list.ejs code is:

<body>
    <h1>Its a <%KindOfDay%> </h1>
</body>

and app.js code is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const express = require("express");
const bodyParser = require("body-parser");


const app = express();

app.set('views', path(__dirname, 'views'));
app.set('view engine', 'ejs');


app.get("/", (req, res) => {

    var today = new Date();
    var currentDate = today.getDate();
    var day = "";

    if (currentDate == 6 || currentDate == 0) {
        day = "Weekend";
    } else {
        day = "Weekday";
    }

    res.render("list", { KindOfDay: day });
console.log(day);
});

app.listen(3000, () => {
    console.log("Server Running");
})

I am providing screenshots and marked in red.

enter image description here

enter image description here

>Solution :

You are wrong tag to display an output. To display output write like this

<%= KindOfDay %>

The one you are using is 'Scriptlet' tag, for control-flow, no output. It is used with loops and if else statements etc.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading