Nodejs: How to access the (process.env) variables of another project?

I have two projects, dataAdapter and main_project placed as follows:

folder:
|___main_project
|   |
|   |___.env
|
|___Packages
    |
    |___dataAdapter

The dataAdapter package is linked to the main_project using:

npm link "../folder/Packages/dataAdapter"

The main_project’s project is configured with the dotenv npm package installed and a dev.env file. I can access the variables from anywhere in the main_project project, but not in my local dataAdapter package.

The .env file in the main_project has the following variables:

DB_CLUSTER_URI=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I thought that I can just use process.env.DB_CLUSTER_URI in the dataAdapter package, but I got undefined instead.

Am I doing something wrong? Isn’t the dataAdapter package running under the same process as the main_project since it’s linked to it? How can I access the DB_CLUSTER_URI in the dataAdapter package from any project that links this package?

Thank you all for your time.

You can make it shared if it is in the root folder or you can use the path option dotenv has.

Edit: maybe I misunderstood your folder structure. Is it in the root?

Thank you for your reply.

The package dataAdapter is independent from the main_project, it can be linked and used by any other project, so I can’t specify a specific path to configure a .env file, instead, it should use the variable from the parent process that’s using it.

I hope this clarified my issue.