node.js - Passing Variable from NodeJS to client-side JS file -
is possible pass server-side javascript variable <script>
tag in html view?
in routes file have:
exports.index = function(req, res){ res.sendfile('views/index.html', { data: {foo: bar} }); };
if using jade template, do:
script(type='text/javascript'). var local_data =!{json.stringify(data)}
to access data
object. however, doesn't work html file. there work-around this?
have route send data using res.json()
, use ajax in html fetch json data.
Comments
Post a Comment