Passing a variable from node.js to html

后端 未结 9 1352
孤独总比滥情好
孤独总比滥情好 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:34

    Other than those on the top, you can use JavaScript to fetch the details from the server. html file

    
    
      
        
        
      
      
          

    server.js

    app.get('/test',(req,res)=>{
        //res.sendFile(__dirname +"/views/test.html",);
        res.json({title:"api",message:"root"});
    })
    
    app.get('/render',(req,res)=>{
        res.sendFile(__dirname +"/views/test.html");
    })
    

    The best answer i found on the stack-overflow on the said subject, it's not my answer. Found it somewhere for nearly same question...source source of answer

提交回复
热议问题