Variables at the server actions folder level

I hope I’m explaining this right, but I want to be able to use variables at the folder level:

image

Which I then can use in the underlying server actions, like {{folder_variable}}. For instance I want to store the username and password of the API I’m calling at the folder level, and then dynamically reference them in the server actions.

If it’s not possible at the folder level, maybe at a global level?

I got the idea from Postman:

image

It makes life a bit easier

Hi Nevil!

That is coincidental- we were just brainstorming about such functionality!!

That it will be really great to have a set of global variables available in all server actions.

Usually such variables are used as config options, database credentials, api end points etc.

And if those are stored per target then you will have your dev and production environments nicely separated and easily switchable.

What do you think @TomD, @mebeingken

4 Likes

Sounds great, if I can be of any help just let me know :slight_smile:

Per target variables are sure to please many! I’ve never considered the need for per folder variables though… not saying it is bad, just hasn’t been a need for me.

1 Like

The need for different local/remote target settings hasn’t been an issue for me, but as @mebeingken says, it will be please many and sounds like a good solution, with additional potential uses/advantages. Variables at the folder level isn’t something I’ve needed or wished for so far, but once it’s an option, I expect it will offer solutions or methods I hadn’t thought of before.

1 Like

I was referring to global variables only, that can have different values per target.

Don’t see additional value to keep them per folder.

1 Like

Environment(target) variables and constants would be a neat addition.

2 Likes

Definitely! :slight_smile:

@George I have seen that the 3.0.2 has:

  • Added new global $_ENV variables to be able to read environment variables server side

But where do you set up the env variable in a node js project ? In .wappler/targets/{target}/.env ?
Or the feature is not finished ?

Thanks a lot !

1 Like

The environment variables have to be set on the server. In plesk you can do that in the admin and with docker you can add it in the docker compose file.

https://nodejs.org/docs/latest/api/process.html#process_process_env

We don’t have a way to set them in your project, we could perhaps add the dotenv package to do that.

2 Likes

That would be handy :slight_smile:

1 Like