#Deno env vars

9 messages · Page 1 of 1 (latest)

north widget
#

In a Deno/Fresh app I have a config file that provides access to env vars, however when I try to run my migrations via

 deno run --env-file=.env db:migrate:latest

which in the deno.json file runs kysely migrate:latest

I am told that Deno is not defined. Is this due to Kysley being a node based lib?

How can I make this work?

export const config: Config = {
    db: {
        host: Deno.env.get('DB_HOST'),
        user: Deno.env.get('DB_USER'),
        password: Deno.env.get('DB_PASSWORD'),
        database: Deno.env.get('DB_NAME'),
        port: parseInt(Deno.env.get('DB_PORT')),
        pool: parseInt(Deno.env.get('DB_POOL_SIZE'))
    }
}
mystic bolt
#

Perhaps use import process from "node:process" then use process.env if it is running from a Node context.

maiden seal
#

are you calling deno run or deno task to run the task from the deno file? If you're using the kysely CLI then it most likely expects to run in a node environment and you'd need to access to env variables as if you were in one for the sake of the migration. Alternatively, I was able to get Kysely migrations to work in Deno by just writing a migrator defined in their docs here: https://kysely.dev/docs/migrations#running-migrations

Migration files

north widget
#

@mystic bolt using node:process did work, not ideal though

#

@maiden seal I was using deno run (wasn't aware of deno task..still learning). I ended up using the migrarion file that you linked to, which allowed me to remove the kysely-ctl lib.

#

Thanks for the help 🙂

maiden seal
#

To be fair, I saw someone mention that deno run and deno task can be used interchangeably to run tasks now. If that's true it's new to me! It used to be use had to call deno task specifically

wooden pelican
# maiden seal are you calling `deno run` or `deno task` to run the task from the deno file? If...

@maiden seal

kysely CLI then it most likely expects to run in a node environment

That's not true. The aim is to be runnable in Deno too. A lot of thought/effort has been put into cross-JS runtime compatibility.

CI is set with 3 variants just for Deno:
https://github.com/kysely-org/kysely-ctl/blob/main/.github/workflows/test.yml#L143-L194

Latest release was Deno-specific:
v0.12.1 - Deno remote imports.

Maybe I got it wrong somewhere or missed something. I don't use Deno in production. This is the point where the community that does use Deno, submits issues OR comes to our Discord and we get stuff solved.

wooden pelican