Skip to content

Commit

Permalink
fix: Early dotenv (#14)
Browse files Browse the repository at this point in the history
* fix: Early dotenv

We need to call `dotenv.config()` before other files are imported to
have the .env configuration take effect in NODE_ENV=production.

* fix: Reorder imports
  • Loading branch information
pettermachado authored Oct 25, 2024
1 parent 594e760 commit c66d77c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
13 changes: 13 additions & 0 deletions lib/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import dotenv from "dotenv";
import { getLogger } from "./logger/index.js";

const logger = getLogger("lib/env");
logger.info("Starting in NODE_ENV=" + process.env.NODE_ENV);

// The dev server parses keys in non-production
if (process.env.NODE_ENV === "production") {
const config = dotenv.config();
logger.info(
"Parsed .env file with keys: " + Object.keys(config.parsed ?? {}).join(","),
);
}
11 changes: 1 addition & 10 deletions server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "./lib/env.js";
import { createRequestHandler } from "@remix-run/express";
import type { ServerBuild } from "@remix-run/node";
import express from "express";
import dotenv from "dotenv";
import pinoHttp from "pino-http";

import { sync } from "./lib/db/index.js";
Expand All @@ -10,15 +10,6 @@ import apiRouter from "./api/index.js";
import { getLogger } from "./lib/logger/index.js";

const logger = getLogger("server");
logger.info("Starting in NODE_ENV=" + process.env.NODE_ENV);

// The dev server parses keys in non-production
if (process.env.NODE_ENV === "production") {
const config = dotenv.config();
logger.info(
"Parsed .env file with keys: " + Object.keys(config.parsed ?? {}).join(","),
);
}

const app = express();
if (process.env.REQUEST_LOG) {
Expand Down

0 comments on commit c66d77c

Please sign in to comment.