# Using dotenv to load environmental variables on a project specific basis

**URL:** <https://discourse.nodered.org/t/using-dotenv-to-load-environmental-variables-on-a-project-specific-basis/91046>\
**Category:** Feature Requests\
**Created:** [17 September 2024 16:15 UTC](https://discourse.nodered.org/t/using-dotenv-to-load-environmental-variables-on-a-project-specific-basis/91046 "2024-09-17T16:15:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![malee](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@malee](https://discourse.nodered.org/u/malee)\
**Post date:** [17 September 2024 16:15 UTC](https://discourse.nodered.org/t/using-dotenv-to-load-environmental-variables-on-a-project-specific-basis/91046/1 "2024-09-17T16:15:58Z")

</div>

This post is a follow up to this initial [feature request](https://discourse.nodered.org/t/feature-request-env-files/88927).

I would post a response but the thread has been closed to replies.

Anyway, I have been having a play with loading environmental variables from file on a project specific basis. It seems like a relatively easy task to accomplish, locally anyway.

I had a look through the node-RED source code and in:

```auto
node_modules\@node-red\runtime\lib\storage\localfilesystem\projects\Project.js

```

Found the method that loads the project during initialization and when a project is switched.

To allow for environmental variables to be loaded on a project specific basis I simply added this line of code to the resolution of all promises:

```auto
return Promise.all(promises).then(function(results) {
	require("dotenv").config({ path: `${project.path}/.env`, override: true });
    return project;
 })

```

It seems to work a treat 🙂

There is a prerequisite for `dotenv` to be included as a dependency and it could be refined to the extent that the override flag `true/false` is included as a project related property in the main settings file.

Anyway it could be a useful feature...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 November 2024 16:16 UTC](https://discourse.nodered.org/t/using-dotenv-to-load-environmental-variables-on-a-project-specific-basis/91046/2 "2024-11-16T16:16:51Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
