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
Release: 2016-05-16 16:27:08
Original
2061 people have browsed it

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);
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