Home >Web Front-end >JS Tutorial >Instructions for using the http.response.write method in node.js_node.js

Instructions for using the http.response.write method in node.js_node.js

WBOY
WBOYOriginal
2016-05-16 16:27:082058browse

Method description:

Send response content to the requesting client.

Before response.end(), response.write() can be executed multiple times.

Grammar:

Copy code The code is as follows:

response.write(chunk, [encoding])

Parameters:

chunk is a buffer or string representing the sent content

encoding If chunk is a string, you need to specify encoding to indicate its encoding method. The default is utf-8

Example:

Copy code The code is as follows:

var http = require('http');
http.createServer(function(req, res){
res.writeHead(200, {'Content-type' : 'text/html'});
res.write('

Node.js

');
res.end('

Hello World

');
}).listen(3000);
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