Node.js response.writeContinue() Method
Last Updated :
23 Sep, 2020
The response.writeContinue() (Added in v0.3.0) method is an inbuilt Application Programming Interface of the ‘http’ module which sends an HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent. See the 'checkContinue' event on Server. The response.writeContinue() is called internally even when no listener is attached.
In order to get a response and a proper result, we need to import ‘http’ module.
Import:
const http = require('http');
Syntax:
response.writeContinue();
Parameters: This method does not accept any parameter.
Return Value: It does not return any value, instead sends an HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent.
The below example illustrates the use of the response.writeContinue() method in Node.js.
Example 1: Program without response.writeContinue() method.
Filename: index.js
javascript
// Node.js program to demonstrate the
// response.writeContinue() Method
// Importing http module
var http = require('http');
// Setting up PORT
const PORT = process.env.PORT || 3000;
// Creating http Server
var httpServer = http.createServer(function(request, response){
// Writing string data
response.write("Heyy geeksforgeeks ", 'utf8', () => {
console.log("Writing Data...");
});
// Defining Buffer 'Hello world'
const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
// Writing the buffer data.
response.write(buf, 'utf8', () => {
console.log("Writing Buffer Data...");
});
// Prints Output on the browser in response
response.end(' ok');
});
// Listening to http Server
httpServer.listen(PORT, () => {
console.log("Server is running at port 3000...");
});
Output:
Output: In-Console
Server is running at port 3000...
Writing Data...
Writing Buffer Data...
Now run http://localhost:3000/ in the browser.
Output: In-Browser
Heyy geeksforgeeks hello world ok
Example 2: Using response.writeContinue() method.
Filename: index.js
javascript
// Node.js program to demonstrate the
// response.writeContinue() Method
// Importing http module
var http = require('http');
// Setting up PORT
const PORT = process.env.PORT || 3000;
// Creating http Server
var httpServer = http.createServer(function(request, response){
// Writing string data
response.write("Heyy geeksforgeeks ", 'utf8', () => {
console.log("Writing Data...");
});
// Using response.writeContinue() method
response.writeContinue();
// Defining Buffer 'Hello world'
const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
// Writing the buffer data.
response.write(buf, 'utf8', () => {
console.log("Writing Buffer Data...");
});
// Prints Output on the browser in response
response.end(' ok');
});
// Listening to http Server
httpServer.listen(PORT, () => {
console.log("Server is running at port 3000...");
});
Run index.js file using the following command:
node index.js
Output:
Output: In-Console
Server is running at port 3000...
Writing Data...
Writing Buffer Data...
Reference: https://nodejs.org/api/http.html#http_response_writecontinue
Similar Reads
Node.js response.write() Method The response.write() (Added in v0.1.29) method is an inbuilt Application program Interface of the âhttpâ module which sends a chunk of the response body that is omitted when the request is a HEAD request. If this method is called and response.writeHead() has not been called, it will switch to implic
3 min read
Node response.writeHead() Method The response.writeHead() property is used to send a response header to the incoming request. It was introduced in Node.js v1.0 and is a part of the 'http' module. The status code represents a 3-digit HTTP status code (e.g., 404), and the headers parameter contains the response headers. Optionally, a
3 min read
Node.js http.ServerResponse.writeProcessing() Method The httpServerResponse.writeProcessing() is an inbuilt application programming interface of class ServerResponse within the HTTP module which is used to send an HTTP/1.1 102 Processing message to the client. Syntax: response.writeProcessing()Parameters: This method does not accept any arguments as a
2 min read
Node response.setHeader() Method The response.setHeader() method in Node.js is used to set HTTP headers for a response. It allows you to define one or more headers for the HTTP response sent by the server. If a header with the same name already exists, its value will be replaced. Additionally, headers can be set as an array of valu
3 min read
Node JS fs.writeFile() Method âIn Node.js, the fs.writeFile() method is a built-in function used to asynchronously write data to a file. This method allows you to create a new file or overwrite an existing one with the specified content, without blocking the event loop, thus maintaining the non-blocking nature of Node.js applica
4 min read
Node.js Stream writable.write() Method The writable.write() method is an inbuilt application programming interface of Stream module which is used to write some data to the Writable stream. The callback function is called once the data has been completely handled. Syntax: writable.write( chunk, encoding, callback) Parameters: This method
2 min read