Skip to content

feat(@angular/build): add process.env.PORT support to the dev server#32705

Open
hawkgs wants to merge 1 commit intoangular:mainfrom
hawkgs:builders/process-env-port-support
Open

feat(@angular/build): add process.env.PORT support to the dev server#32705
hawkgs wants to merge 1 commit intoangular:mainfrom
hawkgs:builders/process-env-port-support

Conversation

@hawkgs
Copy link
Member

@hawkgs hawkgs commented Mar 5, 2026

The change allows setting the dev server port via the PORT environment variable.

BREAKING CHANGE: The @angular/build:dev-server (ng serve) now assigns the highest priority to the PORT environment variable. This value will override any port configurations specified in angular.json or via the --port command-line flag. This includes the default port 4200.

Since the port option is handled by the dev server options JSON schema from what I get, we can only overwrite the already set port (whether that's using the default 4200 or the user-specified --port). This means that process.env.PORT has the highest priority when it comes to port selection unless the port is already in use. I am not sure if this the desired result, precisely, but the alternative would be to drop port from the schema and handle it in the builder execution code instead, if I read the things correctly, which is not an option, I guess.

Resolves #32236

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for setting the dev server port via the PORT environment variable, which is a useful feature for deployment flexibility. The implementation correctly parses and validates the environment variable before applying it. However, there are failing assertions in the newly added test cases that need to be addressed.

@hawkgs hawkgs force-pushed the builders/process-env-port-support branch from 5a5dbfb to d53396e Compare March 5, 2026 15:37
Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hawkgs hawkgs changed the title feat: add process.env.PORT support to dev server builders feat(@angular/build): add process.env.PORT support to the dev server Mar 5, 2026
@hawkgs hawkgs force-pushed the builders/process-env-port-support branch from d53396e to d5c5bc1 Compare March 5, 2026 16:06
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label Mar 5, 2026
@hawkgs
Copy link
Member Author

hawkgs commented Mar 5, 2026

Done. The commit already had a message body but I updated it with the breaking change comment.

Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Resolves #32236 (This should always be part of the footer of the commit not the body. (Tools only handle this in the footer)

  • BREAKING CHANGE: process.env.PORToverwrites both the default port (4200) and the user-specified one using theng serve --port` option. Is not totally correct and it doesn't have "context".

"The @angular/build:dev-server (ng serve) now assigns the highest priority to the PORT environment variable. This value will override any port configurations specified in angular.json or via the --port command-line flag. This includes the default port 4200.

@alan-agius4 alan-agius4 added target: major This PR is targeted for the next major release action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 5, 2026
Make possible to set the dev server port via `process.env.PORT`.

BREAKING CHANGE: The `@angular/build:dev-server (ng serve)` now assigns the highest priority to the `PORT` environment variable. This value will override any port configurations specified in `angular.json` or via the `--port` command-line flag. This includes the default port 4200.

Resolves angular#32236
@hawkgs hawkgs force-pushed the builders/process-env-port-support branch from d5c5bc1 to 1f71a9e Compare March 5, 2026 16:40
Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 5, 2026
@alan-agius4 alan-agius4 closed this Mar 5, 2026
@alan-agius4 alan-agius4 reopened this Mar 5, 2026
@alan-agius4 alan-agius4 removed the action: merge The PR is ready for merge by the caretaker label Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

angular/build:dev-server area: @angular/build detected: breaking change PR contains a commit with a breaking change detected: feature PR contains a feature commit target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support process.env.PORT for ng serve

2 participants