feat(app): add handling for app port from environment variable

This commit imports the `process` module from `node:process` and changes the app to listen on a port specified by an environment variable (APP_PORT). It also adds an error handler to stop the server and log the error message if the server fails to start.

Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
Mathis H (Avnyr) 2024-04-29 09:54:04 +02:00
parent c024770b4a
commit 4ff1aa852d
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -6,6 +6,7 @@ import helmet from "helmet";
import AuthRouter from "@routes/auth/authRouter"; import AuthRouter from "@routes/auth/authRouter";
import CatalogRouter from "@routes/catalog/catalogRouter"; import CatalogRouter from "@routes/catalog/catalogRouter";
import RentRouter from "@routes/rent/rentRouter"; import RentRouter from "@routes/rent/rentRouter";
import * as process from "node:process";
const logger = new Logger({ name: "App" }); const logger = new Logger({ name: "App" });
@ -43,5 +44,10 @@ try {
throw null; throw null;
} }
//app.listen(3333) try {
logger.info('Server is running !') app.listen(process.env["APP_PORT"])
logger.info('Server is running !')
} catch (error) {
logger.error(`Server failed to start: ${error}`);
process.exit(1);
}