[英]When I write simple server, and want to provide static webiste, why don't I have to use utf-8 encoding as it is in the example below?
為什么在提供utf-8編碼時結果相同,而在省略utf-8編碼時結果卻相同?
const http = require('http')
const path = require('path')
const fs = require('fs')
const server = http.createServer((req, res) => {
if (req.url === '/') {
fs.readFile(path.join(__dirname, 'public', 'index.html'), 'utf-8', (err, data) => {
if (err) throw err
res.writeHead(200, {'Content-Type': 'text/html'})
res.end(data)
})
}
})
const PORT = process.env.PORT || 5000
server.listen(PORT, () => console.log('Listening on port ', PORT))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.