'How to add node run option --max-http-header-size and add name to pm2 start command

How would I start a pm2 process with the —max-http-header-size node option, as well as name the process.

I have a server with multiple micro-services, one of the services is a web scraper.

This web scraper accepts requests with headers over the nodejs default 8kb limit. So, to run my app locally have to add the --max-http-header-size node option.

I've cloned my app to the server, but don't know how to set --max-http-header-size, nor do I know how to name the process within the pm2 start command.

So far my attempts have looked like this.

// this sets the name, but I don't know how to add the option `--max-http-header-size`
pm2 start npm --name "{REPONAME}" -- start
pm2 start node --name "scraper" --max-http-header-size 15000 app.js
pm2 start node --max-http-header-size 15000 app.js -- --name "scraper"


Solution 1:[1]

What you're looking for is called environment variables! You can pass environment variables to pm2 using a file that loads your server like this:

module.exports = {
  apps : [
      {
        name: "myapp",
        script: "./app.js",
        watch: true,
        node_args: "--max-http-header-size=16000"
      }
  ]
}

Here's more about it too: https://pm2.keymetrics.io/docs/usage/environment/

Solution 2:[2]

The accepted answer by David Harvey did not work for me as of Node 16. Instead, I had to use node_args, something like this:

{
  "apps" : [{
    "name"        : "myapp",
    "script"      : "./app.js",
    "node_args": "--max-http-header-size=256000",
    "env": {
      "NODE_ENV": "production",
    }
  }]
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jason