0

I have done generating client side js file from php like below

Generate Javascript file with PHP

Curious to know how same can be done in nodejs i'm using dustjs as server side template

<script src="/myjs.js"></script>


app.get('/myjs.js', function (req, res) {

    res.render('myjs'); //myjs can be a  template 

});
Community
  • 1
  • 1
tomalex
  • 1,233
  • 6
  • 17
  • 40
  • 1
    If you're asking, "can I point a script tag's src attribute to a file that is generated dynamically by a NodeJS server", the answer is yes. That's more or less what your example code is doing. Otherwise...what are you asking? – sgress454 Mar 20 '14 at 19:16
  • can i have standalone page which connects to mongodb or different modules, fetch some data and out put the result as js. I think the best bet is to pass the data with render and construct app.get('/myjs.js', function (req, res) { res.render('myjs',{name:"myname"}); //myjs can be a template }); – tomalex Mar 20 '14 at 20:04

0 Answers0