Title
c

Chukwukammadu Anizoba

11/02/2021, 4:36 PM
Hey guys, any idea how to set environment variables (.env) in a Kotlin JS node project? I've tried adding a .env file at the root of the project, but the server code is not picking up the variables from
process.env
. Cheers!
a

Alex Edwards

11/02/2021, 4:38 PM
we do
external val process: dynamic
then we have a function that converts
process.env
from dynamic to
Map<String, String>
but thats not necessary
c

Chukwukammadu Anizoba

11/02/2021, 4:42 PM
Yup, I forgot to mention I already have
external val process: dynamic
in the server code's file. Unfortunately
process.env.PORT
doesn't seem to return anything. For reference, here is the structure of my project:
- server <--- project name
  - src
    - main
      - kotlin
        - main.kt <--- server code
  - .env
And this is the content of my .env file:
PORT=8000
a

Alex Edwards

11/02/2021, 4:49 PM
does
process.env
contain anything or just not your env variables? Personally I don’t actually run node directly in the build script, its an aws env
c

Chukwukammadu Anizoba

11/02/2021, 4:52 PM
process.env
contains all other things except my env variables. I'd imagine this could have to do with where the .env file is placed in the project?
a

Alex Edwards

11/02/2021, 5:05 PM
It might be where the file is placed but i suspect you have to actually tell the run task (or gradle) that it should load that env file and use it
👍🏾 1
the docs are not much help here either https://kotlinlang.org/docs/running-kotlin-js.html
c

Chukwukammadu Anizoba

11/02/2021, 5:15 PM
Yup. Thanks all the same. I'll keep digging and revert as soon as I find something