_64v5w
Last Updated: February 25, 2016
·
696
· iatek
24de118de418063d2370c3aa555a18a5

NodeJS: Render download file to EJS template

Here's a simple way to use NodeJS and Express to render an EJS template that forces a file download. Any JSON objects (ie; foo, bar) are passed through to your EJS template, so that the downloaded file can contain dynamic data from the server...

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

    res.attachment('filename.html');
    res.render('download',{foo:foo, bar: bar));

})