I am tryng to implement a simple REST API with Node Express, but I am not able to put the env file to work in it. There is an .env file in the repository, with the url to the remote database and a couple of other data that are necessary to the project, but is better if they remain hided. Here there is a sample of the dotenv file:
CONNECTION_URL = www.blablabla.com
PASSWORD = admin
PORT = 5000
But it is never opened. In the main code, I wrote as usually the following line to allow it to read and parse the file as needed:
// importing environment variables
require('dotenv').config();
But is seems to not work, in fact I cannot connect to the remote database and choose what port to listend on, and some other stats and variable are not usable. What should I do?
There are two thing to note that I don't think are relevant: this is a Typescript project per se, and I put the .env file into the .gitignore, but as it is present in local, it should not be an issue at all.
I read some stackoverflow question, like the following: dotenv file is not loading environment variables
but this did not solve my problem. It didn't change anything. I also tried to update dotenv and everything.
Nothing else seemed to work properly. Thank you all for your help
EDIT I tried to pass statically the link itself, and it works properly, so the issue is the env file.
I tried also to console.log the process.ENV.CONNECTION_URL, and it returned undefined. It is that for sure