ladjs/dotenv-parse-variables

Variables are not being assigned/parsed into process.env

iagoccampos opened this issue · 3 comments

I'm probably doing something really wrong, but i can't find what...

import dotenv from 'dotenv'
import dotenvParseVariables from 'dotenv-parse-variables'

let env = dotenv.config()
if (env.error || !env.parsed) throw env.error
env = dotenvParseVariables(env.parsed, { assignToProcessEnv: true, overrideProcessEnv: true })
console.log(process.env)

My .env file:

PORT=3000
JWT_SECRET=token

What I got from process.env:

{
  PORT: '3000', // String
  JWT_SECRET: 'token'
}

What I expect:

{
  PORT: 3000, // Number
  JWT_SECRET: 'clinica'
}

What I'm doing wrong?

If you can add a failing test in this repository and submit as a PR that'd be great

I think this issue is related to the fact that process.env will always transform its values into a string.

I've just tested this non-lib-related chunk

process.env["HI"] = 666;
console.log(process.env["HI"], typeof process.env["HI"]);

And for my surprise this is the output
image

You are correct, it will always be a String and cannot be overridden. We assign the variables but you cannot rely on process unless you parse it each time using this library.