Home > Web Front-end > Front-end Q&A > How to set encoding using nodejs

How to set encoding using nodejs

青灯夜游
Release: 2023-02-17 14:16:43
Original
2407 people have browsed it

Method: 1. Use the "res.write("")" statement; 2. Use "res. setHeader()" or "res.writeHeader()" sets the Content-type type.

How to set encoding using nodejs

The operating environment of this tutorial: windows7 system, nodejs version 12.19.0, DELL G3 computer.

Nodejs method of setting encoding

1. Use res.write() to set the meta tag

res.write("<head><meta chartset=&#39;uft-8&#39;/></head>")
Copy after login

2. Use res.setHeader() or res.writeHeader() to set Content-type

res.setHeader("Content-type","text/html;charset=utf8");
res.writeHeader(200,{"Content-type":"text/html;charset=utf8"})
Copy after login

Instructions: Content-Type

Content-Type (content type) generally refers to the Content-Type that exists in a web page. It is used to define the type of network files and the encoding of the web page. It determines in what form and what encoding the browser will read the file. This is often I see that the result of clicking on some PHP web pages is to download a file or an image.

The Content-Type header tells the client the content type of the actual content returned.

Grammar format:

Content-Type: text/html; charset=utf-8
Content-Type: multipart/form-data; boundary=something
Copy after login

[Recommended learning: "nodejs tutorial"]

The above is the detailed content of How to set encoding using nodejs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template