tusharmath / node-config-ts

A simple node configuration manager
61 stars 31 forks source link

Doesn't seem to work with .env files #68

Closed Cmion closed 4 months ago

Cmion commented 3 years ago

The config object returned from node-config-ts is empty.

Steps To Reproduce:

import dotenv from 'dotenv';
dotenv.config();
import {config} from 'node-config-ts';
console.log(config); // Returns {}

Expected behavior: Environment variables from files should be loaded and used in places where @@VAR was used in the JSON files

Typescript Version: 4.2.4 node-config-ts version: 9.1.1

tsconfig.json

{
    "compilerOptions": {
      "target": "es2020",
      "module": "commonjs",
      "outDir": "dist",
      "sourceMap": true,
      "incremental": true,
      "declaration": true,
      "removeComments": true,
      "esModuleInterop": true,
      "resolveJsonModule": true,
      "typeRoots": ["./src/types", "node_modules/@types"],
      "moduleResolution": "node",
    },
    "include": ["src/**/*.ts"],
    "exclude": ["node_modules", ".vscode"]
  }

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "src/main.ts",
  "scripts": {
    "start": "nodemon",
    "postinstall": "node-config-ts"
  },
  "keywords": [],
  "author": "Cmion",
  "license": "MIT",
  "dependencies": {
    "cookie-parser": "^1.4.5",
    "cors": "^2.8.5",
    "dotenv": "^9.0.1",
    "express": "^4.17.1",
    "node-config-ts": "^3.1.0",
    "ts-node": "^9.1.1",
    "typescript": "^4.2.4"
  },
}

Additional context Add any other context about the problem here.

russormes commented 3 years ago

My guess would be dotenv populates the process.env dictionary in the running node process while node-config-ts loads from the environment in the shell the node process is running in. You would need to source your .env file before it would work with the library.

DonIsaac commented 1 year ago

@Cmion we just added support for dotenv, are you still experiencing this issue?