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

2

5

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 .",

Bleacher answered 29/8, 2019 at 7:37 Comment(0)
S
10

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.

Seraphine answered 29/8, 2019 at 8:20 Comment(3)
Hi Ani, thank you for the answer. Yeah i notice that scripts will workbut how can i do it with nodemon and babel-node since i need babel-node to transpile the whole application and nodemon to watch the changesBleacher
"scripts": { "start": "nodemon --max-http-header-size=80000 index.js --exec babel-node --presets babel-preset-env" }Seraphine
with that scripts, it still doesn't work the header size still 8kb I just found another solutions thats work which is add NODE_OPTIONS=--max-http-header-size=80000 before nodemon index.js` No matter what, Thanks for kindly reply and try to help me :)Bleacher
S
0

I'm using ts-node and nodemon, and this works for my project:

"exec": "node --max-http-header-size 80000 -r ts-node/register src/app.ts",

That goes in my nodemon.json config file.

Stoddard answered 21/4, 2023 at 2:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.