1
00:00:01,430 --> 00:00:05,930
We now need to ask this question inside of our Szalai, we have to figure out whether we are running

2
00:00:05,930 --> 00:00:10,940
in a sort of local development mode where if we are running on a user's machine now, unfortunately,

3
00:00:10,940 --> 00:00:14,510
this is going to be another one of those topics inside this course where we kind of just have to write

4
00:00:14,510 --> 00:00:15,920
out a little bit of code right now.

5
00:00:15,950 --> 00:00:20,170
And then it's only going to become a little bit more clear what's going on later on in the future.

6
00:00:20,300 --> 00:00:23,810
So let me try to give you an overview of how we're going to answer this question.

7
00:00:24,960 --> 00:00:30,720
OK, it's a little bit confusing here, like I said, inside of our Seelie, to decide whether or not

8
00:00:30,720 --> 00:00:36,600
we are in production or essentially running on a user's machine or whether we are on our local machine.

9
00:00:36,930 --> 00:00:38,580
We're going to take a look at the process.

10
00:00:38,590 --> 00:00:41,340
EMV node, EMV environment variable.

11
00:00:41,880 --> 00:00:48,180
So node in right here is traditionally set to be a string of development, maybe testing or production.

12
00:00:48,180 --> 00:00:51,730
And we can use that environment variable to decide what environment we are in.

13
00:00:52,530 --> 00:00:56,160
Now, this is an environment variable that is used very often on servers.

14
00:00:56,490 --> 00:01:00,780
So we might have a server or an API that we are putting together and on our local machine, it might

15
00:01:00,780 --> 00:01:01,830
be set to development.

16
00:01:02,070 --> 00:01:07,280
And then when we go and deploy our application to some hosting provider such as US or something similar,

17
00:01:07,800 --> 00:01:10,580
that environment variable would be set to production instead.

18
00:01:11,100 --> 00:01:15,840
Unfortunately, you and I cannot really rely upon this environment variable to closely, and that is

19
00:01:15,840 --> 00:01:21,180
because a user is going to eventually be running this code on their machine and they can very easily

20
00:01:21,180 --> 00:01:24,010
override the value of node and.

21
00:01:25,320 --> 00:01:29,940
They might have a local environment, variable set of note, and it might always be set to development

22
00:01:29,940 --> 00:01:36,030
or testing or something else, so we can't really necessarily rely upon the environment variable itself

23
00:01:36,030 --> 00:01:37,500
to be any particular value.

24
00:01:38,340 --> 00:01:42,570
So instead, we're going to use a little trick here, this is a trick very similar to something we went

25
00:01:42,570 --> 00:01:44,220
over earlier on inside the course.

26
00:01:45,240 --> 00:01:49,440
At some point in time, we're going to take the code for our Seelie and we're going to deploy it off

27
00:01:49,440 --> 00:01:53,790
to 9pm so that other users can run, NPM, install and get Arkley.

28
00:01:54,510 --> 00:02:01,560
Just before you and I deploy our code to NPM, we're going to run a little script that is going to find

29
00:02:01,560 --> 00:02:05,910
every instance of process envy, note envy inside of our code base.

30
00:02:06,210 --> 00:02:10,889
And it's going to replace that reference right there with a string of production.

31
00:02:11,810 --> 00:02:15,860
So inside of all the code that a user is going to actually install on their local machine, there is

32
00:02:15,860 --> 00:02:19,550
never actually going to be any reference to process, envy, envy.

33
00:02:19,790 --> 00:02:23,270
Instead, it's going to be replaced with the string of production.

34
00:02:24,940 --> 00:02:28,000
So with that in mind, let's go back over to our reserve command.

35
00:02:28,240 --> 00:02:30,670
We're going to take a look at why this is going to be so useful.

36
00:02:31,610 --> 00:02:37,550
All right, back inside my editor, I'm going to find my Seelie SIRC commands Servants' file.

37
00:02:38,690 --> 00:02:43,640
Then inside of here at the very top, I'm going to add in a new variable called Is Production.

38
00:02:44,810 --> 00:02:52,490
And I'm going to calculate this thing by comparing process envy, note envy to the string production.

39
00:02:54,460 --> 00:02:58,750
So is production is true, obviously, that means we are probably running on the user's machine or something

40
00:02:58,810 --> 00:02:59,300
like that.

41
00:02:59,980 --> 00:03:00,910
So now here's the key.

42
00:03:00,940 --> 00:03:06,250
Remember, before we take all this code and deploy it off to NPM, where a user can then install our

43
00:03:06,250 --> 00:03:10,240
CLIA, we're going to run that little script that you and I are going to put together in just a little

44
00:03:10,240 --> 00:03:10,550
bit.

45
00:03:10,960 --> 00:03:16,990
That script is going to find inside of our raw script file or really our raw JavaScript file is going

46
00:03:16,990 --> 00:03:19,350
to find that little piece of code right there.

47
00:03:19,840 --> 00:03:23,410
It's going to replace that code with a string production.

48
00:03:25,830 --> 00:03:29,550
So production is always going to be equal to production, and that means that the code that we push

49
00:03:29,550 --> 00:03:33,540
off to NPM will always have a production flag of true.

50
00:03:34,320 --> 00:03:37,080
But whenever you and I are running all this code on our local machine.

51
00:03:38,070 --> 00:03:42,390
This environment variable is probably going to be onsets, or most likely it's probably not going to

52
00:03:42,390 --> 00:03:44,970
or it's definitely not at least going to be equal to string of production.

53
00:03:45,370 --> 00:03:49,560
So whenever you and I are running this code on our local machine, we're going to actually evaluate

54
00:03:49,560 --> 00:03:50,330
this line right here.

55
00:03:50,730 --> 00:03:54,450
Process in the node envy is probably going to be undefined or something like that.

56
00:03:54,640 --> 00:03:55,920
And so we're going to end up with.

57
00:03:55,920 --> 00:03:58,110
And is production of false.

58
00:04:00,350 --> 00:04:04,420
Like I said, this is a little bit challenging to understand, and it's not until we set up that little

59
00:04:04,420 --> 00:04:08,350
script that I mentioned a little bit later on that all this stuff is going to become a little bit more

60
00:04:08,350 --> 00:04:08,710
clear.

61
00:04:09,490 --> 00:04:13,900
Right now, let's just kind of walk away with the assumption that this is production flag is going to

62
00:04:13,900 --> 00:04:18,880
be either true or false, depending upon whether we are running on a user's machine or we are running

63
00:04:18,880 --> 00:04:20,769
on our local development environment.

64
00:04:21,690 --> 00:04:27,440
So we can now use this is production flag and pass it off to our self-command as the fourth argument,

65
00:04:27,990 --> 00:04:34,500
remember service expecting to receive a fourth argument of use proxy and we want to use the proxy if

66
00:04:34,500 --> 00:04:36,180
we are not in production.

67
00:04:37,430 --> 00:04:41,300
It's going to add in as the fourth argument not is production.

68
00:04:43,840 --> 00:04:48,310
So now, if we are in production and is production is true, we're going to flip that over to false

69
00:04:48,460 --> 00:04:50,530
and that means that we do not want to use our proxy.

70
00:04:52,030 --> 00:04:55,900
OK, let's now save this we're going to take a quick pause right here, we'll come back to the next

71
00:04:55,900 --> 00:05:00,910
video and make sure that all this stuff is working as expected in our local development environment.

