Skip to content

Instantly share code, notes, and snippets.

@dhilt
Last active April 8, 2022 17:36
Show Gist options
  • Save dhilt/c47c50070b197b49adaa8abd6af04690 to your computer and use it in GitHub Desktop.
Save dhilt/c47c50070b197b49adaa8abd6af04690 to your computer and use it in GitHub Desktop.
How to set Angular CLI Development Server Port via .env
DEV_SERVER_PORT=4201
{
"name": "my-angular-project",
"version": "0.0.0",
"scripts": {
"start": "node run-env"
},
"dependencies": {
"@angular/animations": "9.1.3",
"@angular/common": "9.1.3",
"@angular/compiler": "9.1.3",
"@angular/core": "9.1.3",
"@angular/platform-browser": "9.1.3",
"@angular/platform-browser-dynamic": "9.1.3",
"@angular/router": "9.1.3",
"core-js": "2.6.11",
"rxjs": "6.5.4",
"tslib": "^1.9.0",
"zone.js": "0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.901.3",
"@angular/cli": "^9.1.3",
"@angular/compiler": "^9.1.3",
"@angular/compiler-cli": "^9.1.3",
"@types/node": "~10.12.0",
"dotenv": "^8.2.0",
"ts-node": "~7.0.0",
"typescript": "~3.5.3"
}
}
const dotenv = require('dotenv');
const child_process = require('child_process');
const config = dotenv.config()
const DEV_SERVER_PORT = process.env.DEV_SERVER_PORT || 4200;
const child = child_process.exec(`ng serve --port=${DEV_SERVER_PORT}`);
child.stderr.on('data', err => console.error(err.toString()));
child.stdout.on('data', data => console.log(data.toString()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment