I am a beginner in node.js and i tried to set up a HTTP server. I came from web Javascript and i know very little about node.js. I tried a code from nodejs.org, which worked, but when i tried characters like this "á" or "Š", it displayed incorrectly.
I tried using libraries like express.js, it fixed the problem, but i am vanilla - i don't like librariess and it proved difficult for me to even show different pages with different URLs.
const http = require('http'); const hostname = '127.0.0.1'; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Vítejte na mojí webové stránce!'); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); The result: VĂtejte na mojĂ webovĂ© stránce!
res.setHeader('Content-Type', 'text/plain; charset=utf-8');googled "http header utf8"