We now need to ask this question inside of our Szalai, we have to figure out whether we are running
in a sort of local development mode where if we are running on a user's machine now, unfortunately,
this is going to be another one of those topics inside this course where we kind of just have to write
out a little bit of code right now.
And then it's only going to become a little bit more clear what's going on later on in the future.
So let me try to give you an overview of how we're going to answer this question.
OK, it's a little bit confusing here, like I said, inside of our Seelie, to decide whether or not
we are in production or essentially running on a user's machine or whether we are on our local machine.
We're going to take a look at the process.
EMV node, EMV environment variable.
So node in right here is traditionally set to be a string of development, maybe testing or production.
And we can use that environment variable to decide what environment we are in.
Now, this is an environment variable that is used very often on servers.
So we might have a server or an API that we are putting together and on our local machine, it might
be set to development.
And then when we go and deploy our application to some hosting provider such as US or something similar,
that environment variable would be set to production instead.
Unfortunately, you and I cannot really rely upon this environment variable to closely, and that is
because a user is going to eventually be running this code on their machine and they can very easily
override the value of node and.
They might have a local environment, variable set of note, and it might always be set to development
or testing or something else, so we can't really necessarily rely upon the environment variable itself
to be any particular value.
So instead, we're going to use a little trick here, this is a trick very similar to something we went
over earlier on inside the course.
At some point in time, we're going to take the code for our Seelie and we're going to deploy it off
to 9pm so that other users can run, NPM, install and get Arkley.
Just before you and I deploy our code to NPM, we're going to run a little script that is going to find
every instance of process envy, note envy inside of our code base.
And it's going to replace that reference right there with a string of production.
So inside of all the code that a user is going to actually install on their local machine, there is
never actually going to be any reference to process, envy, envy.
Instead, it's going to be replaced with the string of production.
So with that in mind, let's go back over to our reserve command.
We're going to take a look at why this is going to be so useful.
All right, back inside my editor, I'm going to find my Seelie SIRC commands Servants' file.
Then inside of here at the very top, I'm going to add in a new variable called Is Production.
And I'm going to calculate this thing by comparing process envy, note envy to the string production.
So is production is true, obviously, that means we are probably running on the user's machine or something
like that.
So now here's the key.
Remember, before we take all this code and deploy it off to NPM, where a user can then install our
CLIA, we're going to run that little script that you and I are going to put together in just a little
bit.
That script is going to find inside of our raw script file or really our raw JavaScript file is going
to find that little piece of code right there.
It's going to replace that code with a string production.
So production is always going to be equal to production, and that means that the code that we push
off to NPM will always have a production flag of true.
But whenever you and I are running all this code on our local machine.
This environment variable is probably going to be onsets, or most likely it's probably not going to
or it's definitely not at least going to be equal to string of production.
So whenever you and I are running this code on our local machine, we're going to actually evaluate
this line right here.
Process in the node envy is probably going to be undefined or something like that.
And so we're going to end up with.
And is production of false.
Like I said, this is a little bit challenging to understand, and it's not until we set up that little
script that I mentioned a little bit later on that all this stuff is going to become a little bit more
clear.
Right now, let's just kind of walk away with the assumption that this is production flag is going to
be either true or false, depending upon whether we are running on a user's machine or we are running
on our local development environment.
So we can now use this is production flag and pass it off to our self-command as the fourth argument,
remember service expecting to receive a fourth argument of use proxy and we want to use the proxy if
we are not in production.
It's going to add in as the fourth argument not is production.
So now, if we are in production and is production is true, we're going to flip that over to false
and that means that we do not want to use our proxy.
OK, let's now save this we're going to take a quick pause right here, we'll come back to the next
video and make sure that all this stuff is working as expected in our local development environment.