node.js - Initializing client javascript variables from nodejs -
i trying send data client using nodejs @ same time server sending html and/or javascript. i'm pretty new web development , overlooking core concept.
here's do.
require('http'); var somevar = 'some data'; http.createserver(function(req, res){ res.writehead(200, {'content-type': 'text/plain'}); res.write(somewebpage); res.sendthisdatatoclient(somevar); res.end(); }).listen(4000);
and client
var somevar = getdatasentwiththispage(); // stuff
i did find way solve specific problem had in different way although still know how / if possible / if javascript way.
you use templating engine , send data so:
res.render('index.html', { myvar : somevar }):
and in index.html you'd have expression evaluating myvar
, example <% myvar %>
in ejs, or span=myvar
in jade.
Comments
Post a Comment