From 62ed122e749db39fdad3336357cc0431082f0006 Mon Sep 17 00:00:00 2001 From: deptyped Date: Fri, 3 May 2024 09:20:35 +0300 Subject: [PATCH] Replace `dotenv` package with built-in `loadEnvFile` --- package-lock.json | 12 ------------ package.json | 1 - src/config.ts | 8 +++++++- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5bec0020..086582c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,6 @@ "@grammyjs/parse-mode": "1.9.0", "@grammyjs/types": "3.5.2", "callback-data": "1.1.1", - "dotenv": "16.4.5", "fastify": "4.26.2", "grammy": "1.21.2", "grammy-guard": "0.5.0", @@ -2065,17 +2064,6 @@ "node": ">=6.0.0" } }, - "node_modules/dotenv": { - "version": "16.4.5", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", - "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://dotenvx.com" - } - }, "node_modules/duplexer": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", diff --git a/package.json b/package.json index 6886c9c9..2e6b2339 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "@grammyjs/parse-mode": "1.9.0", "@grammyjs/types": "3.5.2", "callback-data": "1.1.1", - "dotenv": "16.4.5", "fastify": "4.26.2", "grammy": "1.21.2", "grammy-guard": "0.5.0", diff --git a/src/config.ts b/src/config.ts index b4dd4040..64c5d418 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,8 +1,14 @@ -import "dotenv/config"; +import { loadEnvFile } from "node:process"; import z from "zod"; import { parseEnv, port } from "znv"; import { API_CONSTANTS } from "grammy"; +try { + loadEnvFile(); +} catch { + // No .env file found +} + const createConfigFromEnvironment = (environment: NodeJS.ProcessEnv) => { const config = parseEnv(environment, { NODE_ENV: z.enum(["development", "production"]),