Last Updated: February 25, 2016
·
3.191K
· iatek

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));

})