how to set nodejs command `--max-http-header-size` with `nodemon --exec "babel-node" .`

Kaslie Kaslie picture Kaslie Kaslie · Aug 29, 2019 · Viewed 8.9k times · Source

I am upgrading my nodejs version from 8 to 10. after upgraded, i can't run my application in any browsers right now. so i've been googled my issue and found out that header size of node 10 has been downsized to 8kb from 80kb. my application header size is over 8kb. so i need to set it with nodejs command --max-http-header-size=80000. but i don't know how to set it up with nodemon and babel-node. Please help.

here is my nodemon.json

{
  "ext": "js jsx ejs json gql css",
  "exec": "babel-node"
}

and here is my current package.json:

"develop:server": "BABEL_ENV=server nodemon .",

The Solution i've already tried:

{
  "ext": "js jsx ejs json gql css",
  "exec": "node --max-http-header-size=80000 ./node_modules/babel-cli/bin/babel-node.js"
}

The right solution is below ( choose one of them ):

  1. {
      "ext": "js jsx ejs json gql css",
      "exec": "NODE_OPTIONS=--max-http-header-size=80000 babel-node"
    }
    
  2. "develop:server": "NODE_OPTIONS=--max-http-header-size=80000 BABEL_ENV=server nodemon .",

Answer

Emmanuel Ani picture Emmanuel Ani · Aug 29, 2019

I think node engineers reduced the http-header-size from version 8.16.0. they reduced it to prevent attack like DDOS etc. I had the same problem when i upgraded from node version 8.9.1 to 8.16.0. how i solved the problem was in my package.json, I added --max-http-header-size=80000 flag in start script eg

"scripts": {"start": "node --max-http-header-size=80000 server.js"}

and it worked. but if your header is over 8kb then you have to go back to the previous version until the proper fix comes out.