Hey guys, any idea how to set environment variables (.env) in a Kotlin JS node project? I've tried a...
c
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
we do
Copy code
external val process: dynamic
then we have a function that converts
process.env
from dynamic to
Map<String, String>
but thats not necessary
c
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:
Copy code
- server <--- project name
  - src
    - main
      - kotlin
        - main.kt <--- server code
  - .env
And this is the content of my .env file:
Copy code
PORT=8000
a
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
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
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
Yup. Thanks all the same. I'll keep digging and revert as soon as I find something
1698 Views