vic-3 vic-3 - 19 days ago 5
HTML Question

Passing a variable from node.js to html

I am trying to pass a variable from node.js to my HTML file.

app.get('/main', function(req, res) {
var name = 'hello';
res.render(__dirname + "/views/layouts/main.html", {name:name});

});

Answer

I figured it out I was able to pass a variable like this

<script>var name = "<%= name %>";</script>
console.log(name);