how to pass variable from nodejs (Expressjs) to javascript (client side)

1

I have this fragment of code in nodejs

app.get('/consul', function(req, res, next) { 
  // 
    res.render('c_pUser', { title: conUsers});
});

the title variable I want to pass it to javascript on the client side

try to show it in javascript on the client side like this:

var nuevaVariable=<%=title%>;
alert(nuevaVariable);

but I get an error

How can I pass the nodejs variable to javascript on the client side?

    
asked by hubman 04.12.2016 в 14:17
source

1 answer

1

the solution was:

script(type='text/javascript').
var local_data =!{JSON.stringify(title)}
h3=local_data//mostramos en el archivo .jade
    
answered by 04.12.2016 в 14:53