3

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

5
  • 2
    Set the charset to UTF8. Commented Aug 24, 2014 at 14:28
  • 2
    Have you tried setting the charset with something like `Content-Type: text/plain; charset=utf-8'? Commented Aug 24, 2014 at 14:29
  • Yes I did, but same result Commented Aug 24, 2014 at 18:10
  • 1
    PeterVC's suggesstion should work, IF your script is also stored as UTF-8: in what character set is your script stored? Commented Aug 24, 2014 at 18:18
  • 1
    Bim! Solved :) The code was encoded in ANSI on my Notepad++. Switching the encoding of my *.js file to 'utf-8' ALONG WITH setting the charset in the header solved the issue. I love this community. Thanks a lot. Commented Aug 24, 2014 at 18:22

1 Answer 1

4

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'.

Sign up to request clarification or add additional context in comments.

1 Comment

How to "the *.js file also needs to be encoded in 'utf-8'"?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.