Reputation: 708
I need a simple way to handle this :
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.setHeader('Content-Type', 'text/plain');
res.charset = 'utf-8';
res.end('éàï');
})
app.listen(8080);
So far all I get is this when I request :
http://localhost:8080/ :
���
Edit: if I change the way I set the charset to this :
app.get('/', function(req, res) {
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
res.end('éàï');
})
I actually get this :
���
Thanks, Max
Upvotes: 3
Views: 3026
Reputation: 708
So, with the help of SLaks, PeterVC and Wrikken, here is the answer :
Setting the charset in the header of the response to 'utf-8' is not enough, the *.js file also needs to be encoded in 'utf-8'.
Upvotes: 4