Solution to the garbled code displayed in node.js: 1. View the encoding format of nodeJs through Notepad, and set the encoding format to utf-8; 2. Add encoding instructions to the js file.
The operating environment of this article: Windows 7 system, nodejs v5.10.1 version, Dell G3 computer.
What should I do if node.js displays garbled characters?
Handling of Chinese garbled code problem in nodeJs
Chinese garbled code problem:
Solution steps :
1. First check the encoding format of nodeJs through Notepad. If it is not utf-8, you can set the encoding format to utf-8
2. Add encoding instructions to the js file to let the browser know what encoding to use to interpret the web page
res.writeHead(200,{'Context-Type':'text/html'}); res.write('<head><meta charset="utf-8"/></head>'); //具体实现为这行代码
The result after the solution:
Recommended study:《node.js video tutorial》
The above is the detailed content of What to do if node.js displays garbled characters. For more information, please follow other related articles on the PHP Chinese website!