Node.js http.ServerResponse.writableFinished Property

Last Updated : 23 Jul, 2025

The httpServerResponse.writableFinished is an inbuilt application programming interface of class ServerResponse within http module which is used to check if all the data has been flushed or not.

Syntax:

response.writableFinished

Parameters: This property does not accept any arguments as a parameter.

Return Value: This property returns true if and only if all the data has been flushed or not.

Example 1: Filename: index.js

JavaScript
// Node.js program to demonstrate the
// response.writableFinished APi

// Importing http module
const http = require('http');

// Setting up PORT
const PORT = process.env.PORT || 3000;

// Creating http Server
const httpServer = http.createServer(
    function (request, response) {

        // Checking all the data has been flushed
        // or not by using writableFinished API
        const value = response.writableFinished;


        // Display the result
        // by using end() api
        response.end("Data has been flushed : "
            + value, 'utf8', () => {
                console.log("displaying the result...");

                // Closing the server
                httpServer.close(() => {
                    console.log("server is closed")
                })
            });
    });

// Listening to http Server
httpServer.listen(PORT, () => {
    console.log("Server is running at port 3000...");
});

Run the index.js file using the below command:

node index.js

Console output:

Server is running at port 3000...
displaying the result...
displaying the result...
server is closed
server is closed

Browser Output: Paste the localhost address http://localhost:3000/. In the search bar of the browser.

 Data has been flushed : false

Example 2: Filename: index.js

JavaScript
// Node.js program to demonstrate the
// response.writableFinished APi

// Importing http module
const http = require('http');

// Request and response handler
const http2Handlers = (request, response) => {

    // checking all the data has been flushed or not
    // by using writableFinished API
    const value = response.writableFinished;

    // display result
    // by using end() api
    response.end("Data has been flushed : "
        + value, 'utf8', () => {
            console.log("displaying the result...");

            const value1 = response.writableFinished;
            console.log("Data has been flushed " + value1);
            httpServer.close(() => {
                console.log("server is closed")
            })
        });
};

// Creating http Server
const httpServer = http.createServer(
    http2Handlers).listen(3000, () => {
        console.log("Server is running at port 3000...");
    });

Run the index.js file using the below command:

node index.js

Console Output:

Server is running at port 3000...
displaying the result...
Data has been flushed true

Browser Output: Paste the localhost address http://localhost:3000/. In the search bar of the browser.

Data has been flushed : false

Reference: https://nodejs.org/dist/latest-v12.x/docs/api/http.html#http_response_writablefinished

Comment

Explore