HomeTutorsContact

What is the max HTTP header size in NodeJS server?

By Gulshan Saini
Published in NodeJS
August 17, 2020
1 min read

The default max value of HTTP header size of NodeJS server is

  • 8192 (8KB) for Node version less than 14
  • 16384 (16KB) for Node version greater than 14

Let’s explore how we can inspect and change the max http header size.

Check default HTTP header size

To check the default HTTP header size we can log the value of property maxHeaderSize after creating an instance of http module as follows

const http = require("http");
console.log(`Max HTTP Header size is ${http.maxHeaderSize}`));

Change HTTP header size

We can change the default HTTP header size value via command line while starting the server.

To change the value of http header size from command line, we need to pass argument --max-http-header-size=size while starting the server.

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

Or, if you are using nodemon, you could update the start up script as follows

"start": "nodemon --max-http-header-size=1024 server.js"

Let’s create a simple NodeJS server with following code and save it in file server.js

const http = require('http')

const server = http.createServer((req, res) => {
  res.end(`Server is up \n Max HTTP header size is ${http.maxHeaderSize}`)
})

server.listen(9000, () => {
  console.log(`Server started at port http://127.0.0.1:9000`)
})

Next, open a terminal and navigate to the directory where code for our server is saved.

In the terminal type node --max-http-header-size=1024 server.js.

If you now open URL http://127.0.0.1:9000 in browser, you should see updated value of HTTP headers size.

setting http header size via command line
setting http header size via command line


Tags

#nodejs
Previous Article
How to create a server in NodeJS?

Related Posts

NodeJS
How to create a server in NodeJS?
August 16, 2020
1 min
Gulshan Saini

Gulshan Saini

Fullstack Developer

Topics

Flutter
JavaScript
NextJS
ReactJS
Typescript

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.
© 2021, All Rights Reserved.

Quick Links

Contact UsBrowserCSSPythonPuppeteer

Social Media