Skip to content
Related Articles

Related Articles

Improve Article

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




// 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




// 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




My Personal Notes arrow_drop_up
Recommended Articles
Page :