10

I create multiple apps using nx monorepo, but when I try to run nx run-many to start all apps at once, but I got the error that the port is already taken, which is true.

when I run apps one at a time, I can specify a port, but on run-many i can't. so is there any way to set the default port for every app?

Thanks in advance.

Kousher Alam
  • 1,005
  • 1
  • 15
  • 30

1 Answers1

27

You can set the configuration of your React apps by editing project.json file

"serve": {
    "executor": "@nrwl/web:dev-server",
    "options": {
        "buildTarget": "admin:build",
        "hmr": true,
        "port": 3001
    },
    "configurations": {
        "production": {
            "buildTarget": "admin:build:production",
            "hmr": false
        }
    }
}

Under every command you want to execute, there is an options key which you can add port.

PaulMest
  • 12,925
  • 7
  • 53
  • 50
Ali
  • 615
  • 10
  • 16
  • 2
    Please [edit] your answer to include the code (or, in this case, JSON) as text, and then format it using Markdown. Don’t include code as a screenshot. – Jeremy Caney Dec 15 '21 at 00:13
  • 1
    To be noted, ports below 1024 will not work by default. For example: If you want to run your app at port 80, have to setup port forwarding from port 80 to your default port for nx app. – manojadams Dec 29 '22 at 06:21