Node.js http.IncomingMessage.statusCode Method Last Updated : 05 Apr, 2023 Comments Improve Suggest changes Like Article Like Report The http.IncomingMessage.statusCode is an inbuilt application programming interface of class IncomingMessage within HTTP module which is used to get the 3-digit HTTP response status code. Syntax: const message.statusCodeParameters: This method does not accept any argument as a parameter. Return Value: This method returns the 3-digit HTTP response status code. Example 1: Filename: index.js JavaScript // Node.js program to demonstrate the // request.statusCode method // 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) { // Getting statusCode // by using request.statusCode method const value = request.statusCode; console.log(value) console.log(response.statusCode) // Display result response.end("statusCode : " + value, 'utf8', () => { console.log("displaying the result..."); 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 following command. node index.jsOutput: Server is running at port 3000... null 200 displaying the result... server is closedNow go to http://localhost:3000/ in the browser, and you will see the following output: statusCode : nullExample 2: Filename: index.js JavaScript // Node.js program to demonstrate the // request.statusCode method // Importing http module const http = require('http'); // Request and response handler const http2Handlers = (request, response) => { // Getting statusCode // by using request.statusCode method const value = request.statusCode; const msg = '' if (!value) { msg = 'Request statusCode Not Set' } else { msg = 'Request statusCode Set' } // Display result response.end(msg, 'utf8', () => { console.log("displaying the result..."); 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 following command. node index.jsOutput: Server is running at port 3000... displaying the result... server is closedNow go to http://localhost:3000/ in the browser, and you will see the following output: Request statusCode Not SetReference: https://nodejs.org/dist/latest-v12.x/docs/api/http.html#http_message_statuscode Comment More infoAdvertise with us Next Article Node.js http.IncomingMessage.httpVersion Method rohitprasad3 Follow Improve Article Tags : Web Technologies Node.js Node.js-Methods Node.js-HTTP-Module Similar Reads http.Agent MethodNode.js new Agent() MethodThe Node.js HTTP API is low-level so that it could support the HTTP applications. In order to access and use the HTTP server and client, we need to call them (by ârequire(âhttpâ)â). HTTP message headers are represented as JSON Format. The new Agent({}) (Added in v0.3.4) method is an inbuilt applicat 4 min read Node.js agent.createConnection() MethodThe Node.js HTTP API is low-level so that it could support the HTTP applications. In order to access and use the HTTP server and client, we need to call them (by ârequire(âhttpâ)â). HTTP message headers are represented as JSON Format. The agent.createConnection() (Added in v0.11.4) method is an inbu 2 min read Node.js agent.maxSockets MethodThe Node.js HTTP API is low-level so that it could support the HTTP applications. In order to access and use the HTTP server and client, we need to call them (by ârequire(âhttpâ)â). HTTP message headers are represented as JSON Format. The agent.maxSockets (Added in v0.3.6) method is an inbuilt appli 2 min read Node.js agent.maxFreeSockets MethodThe Node.js HTTP API is low-level so that it could support the HTTP applications. In order to access and use the HTTP server and client, we need to call them (by ârequire(âhttpâ)â). HTTP message headers are represented as JSON Format. The agent.maxFreeSockets (Added in v0.11.7) method is an inbuilt 2 min read http.Server PropertiesNode.js http.ClientRequest.connection PropertyThe http.ClientRequest.connection is an inbuilt application programming interface of class ClientRequest within the HTTP module which is used to get the reference of underlying client request socket. Syntax: const request.connectionParameters: It does not accept any argument as the parameter. Return 2 min read Node.js http.ClientRequest.aborted PropertyThe http.ClientRequest.aborted is an inbuilt application programming interface of class Client Request within http module which is used to check if the client request has been aborted or not. Syntax: request.aborted Parameters: It does not accept any argument as a parameter. Return Value: It does no 2 min read Node.js http.ClientRequest.path PropertyThe http.ClientRequest.path is an inbuilt application programming interface of class ClientRequest within HTTP module which is used to get the request path for the particular client request. Syntax: request.pathParameters: This property does not accept any argument as a parameter. Return Value: This 2 min read Node.js http.ClientRequest.reusedSocket PropertyThe http.ClientRequest.reusedSocket is an inbuilt application programming interface of class ClientRequest within the HTTP module which is used to check if the request is sent through a reused socket. Syntax: const request.reusedSocketParameters: This property does not accept any argument as a param 2 min read Node.js http.ClientRequest.socket PropertyThe http.ClientRequest.socket is an inbuilt application programming interface of class ClientRequest within HTTP module which is used to get a Proxy object that acts as a net.Socket. Syntax: request.socketParameters: This property does not accept any argument as a parameter. Return Value: This prope 2 min read http.Server MethodsNode.js http.ClientRequest.abort() MethodThe http.ClientRequest.abort() is an inbuilt application programming interface of class Client Request within http module which is used to abort the client request. Syntax: ClientRequest.abort() Parameters: This method does not accept any argument as a parameter. Return Value: This method does not r 2 min read Node.js http.ClientRequest.protocol MethodThe http.ClientRequest.protocol is an inbuilt application programming interface of class ClientRequest within the HTTP module which is used to get the object of client request protocol. Syntax: const request.protocolParameters: This function does not accept any argument as a parameter. Return Value: 2 min read Node.js http.ClientRequest.setNoDelay() MethodThe http.ClientRequest.setNoDelay() is an inbuilt application programming interface of class ClientRequest within HTTP module which is used to set the socket such as delaying of excessive requests while requests are being limited is not desired. Syntax: const request.setNoDelay([noDelay])Parameters: 2 min read Node.js http.ClientRequest.removeHeader() MethodThe http.ClientRequest.removeHeader() is an inbuilt application programming interface of class ClientRequest within the HTTP module which is used to remove a header that's already defined into the headers object. Syntax: const request.removeHeader(name)Parameters: This method takes the name of the h 2 min read Node.js http.ClientRequest.setHeader() MethodThe http.ClientRequest.setHeader() is an inbuilt application programming interface of class ClientRequest within the HTTP module which is used to set the object of the header. Syntax: const request.setHeader(name, value)Parameters: This method takes the name and value of the particular header as a p 2 min read Node.js http.ClientRequest.setTimeout() MethodThe http.ClientRequest.setTimeout() is an inbuilt application programming interface of class ClientRequest within the HTTP module which is used to set the request time out for the client request. Syntax: request.setTimeout(timeout[, callback])Parameters: This method takes the time out value as a par 2 min read http.Serverv PropertiesNode.js http.server.timeout PropertyThe http.server.timeout is an inbuilt application programming interface of class Server within the HTTP module which is used to get the default Timeout value in milliseconds. In Node.js, the default server timeout is 0 milliseconds for the latest version and 2min i.e. (120000 milliseconds) for the o 3 min read Node.js http.server.maxHeadersCount PropertyThe http.server.maxHeadersCount is an inbuilt application programming interface of class Server within the HTTP module which is used to get the maximum number of incoming headers to count. Syntax: const server.maxHeadersCountParameters: This property does not accept any argument as a parameter. Retu 3 min read Node.js http.server.listening PropertyThe http.server.listening is an inbuilt application programming interface of class Server within http module which is used to check if the server is listening for connection or not. Syntax: const server.listening Parameters: It does not accept any argument as a parameter. Return Value: It does not r 3 min read Node.js http.server.keepAliveTimeout PropertyThe http.server.keepAliveTimeout is an inbuilt application programming interface of class Server within http module which is used to get the number of milliseconds of inactivity a server needs to wait for additional incoming data. Syntax: server.keepAliveTimeout Parameters: This API does not accept 3 min read http.Server MethodsNode.js http.server.close() MethodThe http.server.close() is an inbuilt application programming interface of class Server within the HTTP module which is used to stop the server from accepting new connections. Syntax: const server.close([callback])Parameters: This method accepts only one optional callback function argument as a para 2 min read Node.js http.server.headersTimeout MethodThe http.server.headersTimeout is an inbuilt application programming interface of class Server within the HTTP module which is used to get the time the parser will wait to receive the complete HTTP headers. Syntax: server.headersTimeoutParameters: This method does not accept any arguments as a param 2 min read Node.js http.server.listen() MethodThe http.server.listen() is an inbuilt application programming interface of the class Server within the HTTP module which is used to start the server by accepting new connections. Syntax: const server.listen(options[, callback])Parameters: This method accepts the following two parameters: option: It 2 min read http.ServerResponse PropertiesNode.js http.ServerResponse.writableEnded PropertyThe httpServerResponse.writableEnded is an inbuilt application programming interface of class Server Response within http module which is used to check if response.end() has been called or not. Syntax: response.writableEnded Parameters: This method does not accept any parameter. Return Value: This m 2 min read Node.js http.ServerResponse.statusCode PropertyThe httpServerResponse.statusCode is an inbuilt application programming interface of class ServerResponse within the HTTP module which is used to this property controls the status code that will be sent to the client when the headers get flushed. Syntax: const response.statusCodeParameters: This pro 2 min read Node.js http.ServerResponse.headersSent PropertyThe httpServerResponse.headersSent is an inbuilt application programming interface of class ServerResponse within the HTTP module which is used to check if the header has been sent or not. Syntax: const response.headersSentParameters: This property does not accept any arguments as a parameter. Retur 2 min read Node.js http.ServerResponse.statusMessage PropertyThe httpServerResponse.statusMessage is an inbuilt application programming interface of class ServerResponse within http module which is used to control the status message that will be sent to the client when the headers get flushed. Syntax: response.statusMessage Parameters: This method does not ac 2 min read http.ServerResponse MethodsNode.js http.ServerResponse.writeProcessing() MethodThe 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.js http.ServerResponse.sendDate MethodThe httpServerResponse.sendDate is an inbuilt application programming interface of class Server Response within http module which is used to check if the date header has been sent or not. HTTP header is also used to pass additional information such as Date etc. Refer to this article. Syntax: respons 2 min read Node.js http.ServerResponse.end() MethodThe httpServerResponse.end() is an inbuilt application programming interface of class Server Response within http module which is used to send the signal to the server that all the header has been sent. Syntax: response.end(data, Encodingtype, Callbackfunction) Parameters: This method takes three Pa 2 min read Node.js http.ServerResponse.connection MethodThe httpServerResponse.connection is an inbuilt application programming interface of class Server Response within http module which is used to get the response socket of this HTTP connection. Syntax: response.connection Parameters: This method does not accept any argument as a parameter. Return Valu 2 min read http.IncomingMessage MethodsNode.js http.IncomingMessage.trailers MethodThe http.IncomingMessage.trailers is an inbuilt application programming interface of the class Incoming Message within http module which is used to get the request/response trailers to object. Syntax: request.trailers or response.trailers Parameters: This method does not accept any argument as a par 2 min read Node.js http.IncomingMessage.statusMessage MethodThe http.IncomingMessage.statusMessage is an inbuilt application programming interface of the class Incoming Message within http module which is used to get the HTTP response status message. Syntax: message.statusMessage Parameters: This method does not accept any argument as a parameter. Return Val 2 min read Node.js http.IncomingMessage.method MethodThe http.IncomingMessage.method is an inbuilt application programming interface of class Incoming Message within the inbuilt http module which is used to get the type of request method as a string. Syntax: request.method Parameters: This method does not accept any argument as a parameter. Return Val 2 min read Node.js http.IncomingMessage.rawHeaders MethodThe http.IncomingMessage.rawHeaders is an inbuilt application programming interface of class Incoming Message within http module which is used to get the raw request/response headers to list exactly as they were received. Syntax: request.rawHeaders Parameters: This method does not accept any argumen 2 min read Node.js http.IncomingMessage.statusCode MethodThe http.IncomingMessage.statusCode is an inbuilt application programming interface of class IncomingMessage within HTTP module which is used to get the 3-digit HTTP response status code. Syntax: const message.statusCodeParameters: This method does not accept any argument as a parameter. Return Valu 2 min read Node.js http.IncomingMessage.rawTrailers MethodThe http.IncomingMessage.rawTrailers is an inbuilt application programming interface of class IncomingMessage within HTTP module which is used to get the raw request/response trailer keys and values exactly as they were received. Syntax: const message.rawTrailersParameters: This method does not acce 2 min read Node.js http.IncomingMessage.aborted MethodThe http.IncomingMessage.aborted is an inbuilt application programming interface of class IncomingMessage within the HTTP module which is used to check if the request has been aborted or not. Syntax: const message.abortedParameters: This method does not accept any argument as a parameter. Return Val 2 min read Node.js http.IncomingMessage.headers MethodThe http.IncomingMessage.headers is an inbuilt application programming interface of class IncomingMessage within the HTTP module which is used to get all the request/response headers objects. Syntax: const message.headersParameters: This method does not accept any argument as a parameter. Return Val 2 min read Node.js http.IncomingMessage.httpVersion MethodThe http.IncomingMessage.httpVersion is an inbuilt application programming interface of the class Incoming Message within http module which is used to get the HTTP version sent by the client. The most commonly used version is HTTP/1.1. Syntax: request.httpVersion Parameters: This method does not acc 2 min read Node.js http.IncomingMessage.complete MethodThe http.IncomingMessage.complete is an inbuilt application programming interface of class IncomingMessage within http module which is used to check if a complete HTTP message has been received and successfully parsed or not. Syntax: const message.complete Parameters: This method does not accept any 2 min read Like