I'm using node.js and express and I want to download a current file that is in a specific directory in my server side.
I tried as follows. There is no error but there is no file that is downloaded in my disk too.
What is my wrong?
app.get('/getFile', function(req, res){
res.download('public/example.pem');
});
Also I tried that too
app.get('/getFile', function(req, res){
var filename = path.basename('public/example.pem');
res.setHeader('Content-Disposition', 'attachment; filename=' + filename);
res.setHeader('Content-Type', 'application/x-pem-file');
var filestream = fs.createReadStream('public/example.pem');
filestream.pipe(res);
});