Home  >  Article  >  Web Front-end  >  What to do if node.js displays garbled characters

What to do if node.js displays garbled characters

藏色散人
藏色散人Original
2021-12-10 11:32:195305browse

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.

What to do if node.js displays garbled characters

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(&#39;<head><meta charset="utf-8"/></head>&#39;);   //具体实现为这行代码

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn