Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

node.js
communitycreator

What is the Node `http.maxHeaderSize` property?

Ayush Trivedi

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

In this shot, we will learn how to use the http.maHeaderSize property. Headers are important in request and response and contain additional details about the request and response data. A header is an object with a name and value assigned to it.

The http.maxHeaderSize property returns the maximum size of a header that HTTP supports. The different versions of Node have different sizes; for example, Node version >14 has a max size of 16kb, whereas Node version <14 has a max size of 8kb.

Code

Let’s try to find out the maximum size of header HTTP supports.

const http = require("http");
let size = http.maxHeaderSize;
console.log('Max HTTP Header size is', size);

Code explanation

  • In line 1, we import the built-in http module of Node and create a variable.

  • In line 3, we create a variable and store the value returned from the http.maxHeaderSize property.

  • In line 4, we use console.log() to print the value on the screen.

Output

The console prints the value 8192, which is around 8kb. Since the version of Node in the window is less than 14, we have a max size of 8kb. If you execute this code in the latest version of Node or any version greater than 14, you will get a value of 16kb.

How to change the header size

Node provides us with different ways to change the header size. When you run node server.js, just add the line --max-http-header-size=1024 before server.js and you can change the value 1024.

Below is the syntax to run the command.

node --max-http-header-size=1024 server.js

Try this in your personal machine and see if it works.

RELATED TAGS

node.js
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring