Download String As File Express Js

[Solved] Download String As File Express Js | Javascript Frameworks Express - Code Explorer | yomemimo.com
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

Answers related to download string as file express js

Code Explorer Popular Question For Javascript Frameworks Express