Not directly Rust related but still. Tried to config built ds bot on poise and serenity and got confused

I have database connected to my discord bot through .env and dotenvy crate. I'm using sqlx with sqlite and db url is the same directory as root dir, but my app can access this info ONLY through env file or env var.

I'm using nssm to create a service for ds bot to run there without needing terminal opened. I didnt configure it and don't even know how if its even possible. In regedit i didn't change anything for my service and also there is no .env file in root directory where my executable located, but somehow my bot still works, db works as well.

I'm confused where my app takes db url

It looks like NSSM has the ability to pass environment variables directly: scroll down to "Environment tab".

yeah, that's good to know. Thanks
But still don't know how my app gets its connection string for db.
To be clear i didn't configure anything outside of my app, and inside of it there is only env file with db conn in it, but in exe enviroment there is no .env file

How are you reading your .env file? Maybe you are reading it during compile time and not at run time?

Im using dotenvy crate. it looks like

dotenvy::dotenv().ok();

maybe this crate compiles my .env file

Tbh it looks like true for me because i can execute it through cmd and as service without .env file and it works perfectly fine

No, dotenvy::dotenv reads the environment file during run time. Note that it reads .env files in the working directory and all the parent directories. By calling ok(), we never actually know if dotenvy found an environment file or if the program's environment contained the correct variables without being able to read an environment file. The result of a successful call to dotenv returns the path of the environment file. You could print it to see what dotenvy finds (or in case the call returns an io::ErrorKind::NotFound error, we know that no file was found).

Oh it makes more sence now.
tommorow ill check if my project .env file is how my built app gets connection string

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.