Implement .env support for PORT property

This commit is contained in:
stretch07 2024-03-12 22:42:13 -07:00
parent e030321da0
commit 06fc54b18e
No known key found for this signature in database
GPG Key ID: BF61A07A20C8E417
5 changed files with 24 additions and 4 deletions

1
.env.example Normal file
View File

@ -0,0 +1 @@
PORT=4000

3
.gitignore vendored
View File

@ -6,3 +6,6 @@ license.config.json
license-header.txt
dist/
.vscode/
.env
# this is for jetbrain IDEs
.idea/

View File

@ -2,9 +2,11 @@ const express = require("express");
const { generateDevHtml, build } = require("./utils.js");
const { argv } = require('node:process');
const chalk = require('chalk');
const dotenv = require('dotenv');
dotenv.config();
const app = express();
let port = 4000; // Starting port
let port = process.env.PORT ?? 4000; // Starting port
const maxAttempts = 10; // Maximum number of ports to try
const env = argv[2] ?? "dev";

13
package-lock.json generated
View File

@ -11,6 +11,7 @@
"devDependencies": {
"chalk": "^4.1.0",
"clean-css": "^5.3.2",
"dotenv": "^16.4.5",
"express": "^4.18.2",
"html-entities": "^2.3.3",
"nodemon": "^2.0.22",
@ -781,6 +782,18 @@
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/dotenv": {
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"dev": true,
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",

View File

@ -11,11 +11,12 @@
"devDependencies": {
"chalk": "^4.1.0",
"clean-css": "^5.3.2",
"html-entities": "^2.3.3",
"webpack": "^5.88.2",
"dotenv": "^16.4.5",
"express": "^4.18.2",
"html-entities": "^2.3.3",
"nodemon": "^2.0.22",
"uglify-js": "^3.17.4",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.1"
},
"scripts": {