Node.js / Express - How do I set response character encoding?

express, javascript, node.js

Solution

Use res.charset: http://expressjs.com/api.html#res.charset

res.charset = 'value';
res.send('some html');
// => Content-Type: text/html; charset=value

However, JSON is UTF-8 by default so you don't need to set anything.

Problem

Say I got: ``` app.get('/json', function(req, res) { res.set({ 'content-type': 'application/json' }).send('{"status": "0"}'); }); ``` I'm trying to send the response as UTF-8 with the following with no success: ``` app.get('/json', function(req, res) { // From Node.js Official Doc // http://nodejs.org/api/http.html#http_http_request_options_callback res.setEncoding('utf8'); res.set({ 'content-type': 'application/json' }).send('{"status": "0"}'); }); ``` What is the correct way to set character encoding in Express?

Original source