Question : download string as file express js
Answered by : ender1324
app.get('/download', (request, response) => { const fileData = 'SGVsbG8sIFdvcmxkIQ==' const fileName = 'hello_world.txt' const fileType = 'text/plain' response.writeHead(200, { 'Content-Disposition': `attachment; filename="${fileName}"`, 'Content-Type': fileType, }) const download = Buffer.from(fileData, 'base64') response.end(download)
})
Source : https://newbedev.com/node-express-js-download-file-from-memory-filename-must-be-a-string | Last Update : Wed, 17 Nov 21