When you develop an application with Express or another framework, you will need to setup differents environments like
Before running our app we can simply set the environment variable to production:
A better way is to set it inside our
We now have access to that variable inside our app.
To make things easier and to set multiple variables we will use node Node foreman.
Foreman is a manager for Procfile-based applications. Its aim is to abstract away the details of the Procfile format, and allow you to either run your application directly or export it to some other process management format.
First, we need to install globally:
Second we need to create a new file called
.env at the root of our project.
We can now setup our variables :
We need to add a new script inside
Now we can run our app with the
nf command from node Foreman module that we just installed :
Voilà. We now have a clean and flexible setup depending of our environments.