Skip to content

Commit

Permalink
fix(config): 🐛 move environment vars loading to server.ts
Browse files Browse the repository at this point in the history
- Remove loadEnvironmentVariables() function invocation from config/index.ts and move to server.ts
- Ensure environment variables are loaded before validating them.
  • Loading branch information
navin-moorthy committed May 4, 2023
1 parent 2d2f2f0 commit e6955d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export const loadEnvironmentVariables = (): void => {
config({ path: `.env.${process.env.NODE_ENV ?? "development"}` });
};

loadEnvironmentVariables();

/**
* The environment the application is running in.
*/
Expand Down
6 changes: 0 additions & 6 deletions src/index.ts

This file was deleted.

19 changes: 19 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import http, { type IncomingMessage, type ServerResponse } from "node:http";

import { loadEnvironmentVariables } from "./config";
import { validateEnvironmentVariables } from "./config/validateEnvironment";

loadEnvironmentVariables();
validateEnvironmentVariables();

const server = http.createServer(
(_request: IncomingMessage, response: ServerResponse) => {
response.writeHead(200, { "Content-Type": "text/plain" });
response.end("Hello, World!");
},
);

server.listen(3_000, () => {
// eslint-disable-next-line no-console
console.log("Server is listening on port 3000");
});

0 comments on commit e6955d1

Please sign in to comment.