Passing a variable from node.js to html

后端 未结 9 1380
孤独总比滥情好
孤独总比滥情好 2020-11-27 18:12

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 + \"/view         


        
9条回答
  •  鱼传尺愫
    2020-11-27 18:29

    I have achieved this by a http API node request which returns required object from node object for HTML page at client ,

    for eg: API: localhost:3000/username

    returns logged in user from cache by node App object .

    node route file,

    app.get('/username', function(req, res) {
        res.json({ udata: req.session.user });
        });
    

提交回复
热议问题