Complete the code to send a file named 'report.pdf' for download using Express.
app.get('/download', (req, res) => { res.[1]('report.pdf'); });
The res.download() method sends a file as an HTTP attachment, prompting the user to download it.
Complete the code to specify a custom filename 'user_report.pdf' for the downloaded file.
app.get('/download', (req, res) => { res.download('report.pdf', [1]); });
The second argument to res.download() sets the filename the user sees when downloading.
Fix the error in the code to handle errors during file download.
app.get('/download', (req, res) => { res.download('report.pdf', ([1]) => { if (err) { res.status(500).send('Error downloading file'); } }); });
The callback receives an error object named err by convention to check if the download failed.
Fill both blanks to send 'report.pdf' for download and handle errors by sending a 404 status.
app.get('/download', (req, res) => { res.[1]('report.pdf', ([2]) => { if ([2]) { res.status(404).send('File not found'); } }); });
res.download sends the file, and the callback receives err to check for errors.
Fill all three blanks to send 'report.pdf' for download with a custom filename 'summary.pdf' and handle errors by logging them.
app.get('/download', (req, res) => { res.[1]('report.pdf', [2], ([3]) => { if ([3]) { console.error('Download error:', [3]); res.status(500).send('Download failed'); } }); });
The res.download method takes the file path, the custom filename, and a callback with an error parameter.