serve a file in express
const express = require('express')
const app = express()
app.use(express.static(__dirname + '/dist'))
app.get('/', (_, res) => {
res.sendFile('index.html')
})
app.listen(3000)
serve a file in express
const express = require('express')
const app = express()
app.use(express.static(__dirname + '/dist'))
app.get('/', (_, res) => {
res.sendFile('index.html')
})
app.listen(3000)
download string as file express js
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)
})
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us