1
00:00:01,160 --> 00:00:06,590
Our action function now has that file name and the port, these are two pieces of information that we

2
00:00:06,590 --> 00:00:12,080
really want to communicate over to our local API because remember, the entire goal of that local API

3
00:00:12,230 --> 00:00:16,760
is to serve up our react application number one, and then two other jobs are associated with it.

4
00:00:17,060 --> 00:00:20,600
It needs to also save cells into a very particular file.

5
00:00:20,730 --> 00:00:23,420
So that's the name of the file that was communicated to the Seelie.

6
00:00:23,840 --> 00:00:26,620
And it needs to also fetch cells from that file as well.

7
00:00:27,480 --> 00:00:33,300
So when a user runs this server, commands Arkley, we then need to take that file name and the port

8
00:00:33,300 --> 00:00:36,340
and start up a local Express API.

9
00:00:36,780 --> 00:00:41,130
So how are we going to communicate this information over to the local API when we start it up?

10
00:00:41,730 --> 00:00:44,280
Well, we're going to use a very simple and straightforward approach.

11
00:00:46,270 --> 00:00:51,880
From our local API package, we're going to export a function called serve this serve function is going

12
00:00:51,880 --> 00:00:54,250
to be a function that starts up an express server.

13
00:00:54,700 --> 00:00:59,620
The arguments to serve are going to be the part that we want to run our server on the name of the file

14
00:00:59,650 --> 00:01:04,180
that we want to store cells inside of, and then the directory of that file as well.

15
00:01:04,209 --> 00:01:05,530
That's what is right there.

16
00:01:06,750 --> 00:01:11,580
Right now, our Seelie or the surf command really knows the port and knows the name of the file that

17
00:01:11,580 --> 00:01:15,810
we want to store that list of cells inside of, and then we can definitely also figure out the directory

18
00:01:15,810 --> 00:01:16,940
of that file as well.

19
00:01:18,010 --> 00:01:22,030
So we need to import the search function that we're going to write out in just a little bit into our

20
00:01:22,030 --> 00:01:24,410
Seelie, specifically into the search command.

21
00:01:24,970 --> 00:01:28,930
We're then going to call that search function with a port, with a file name.

22
00:01:30,560 --> 00:01:32,750
And with the directory of that file as well.

23
00:01:33,820 --> 00:01:37,930
So then, like I said, inside the search function, we're going to start up our express server, we're

24
00:01:37,930 --> 00:01:42,940
going to listen for traffic on that given port and then start to fetch and save cells into the given

25
00:01:42,940 --> 00:01:43,410
file.

26
00:01:43,960 --> 00:01:44,940
And that's pretty much it.

27
00:01:45,820 --> 00:01:49,990
Now, just as a very quick aside here, I know that some of the stuff, particularly around the file

28
00:01:49,990 --> 00:01:53,920
and how we're going to save cells and fetch cells from it might be just a little bit confusing.

29
00:01:54,070 --> 00:01:57,030
I would recommend you not going to get too lost in that aspect.

30
00:01:57,160 --> 00:02:01,990
Saving and loading cells from a file is going to be at the other day a lot more straightforward than

31
00:02:01,990 --> 00:02:02,660
you might think.

32
00:02:03,070 --> 00:02:06,810
So it just feels like to me that part is a little bit a little murky right now.

33
00:02:06,820 --> 00:02:10,870
And if it is really don't sweat it, it's going to become crystal clear as soon as we start working

34
00:02:10,870 --> 00:02:11,260
with it.

35
00:02:12,200 --> 00:02:17,930
OK, so this is our general goal, so we need to go back over to our local API, we're going to create

36
00:02:17,930 --> 00:02:20,600
a search function that's going to take these different arguments.

37
00:02:20,870 --> 00:02:23,750
And then right now inside there, we'll just do a console log of those arguments.

38
00:02:24,470 --> 00:02:29,720
We'll then import the search function over into our server command inside the Seelie and just try to

39
00:02:29,720 --> 00:02:30,140
call it.

40
00:02:30,330 --> 00:02:32,780
So just a very simple intermediate step right now.

41
00:02:33,740 --> 00:02:35,270
All right, let's go back over to our Ed.

42
00:02:36,320 --> 00:02:40,550
I'm going to find my local API package inside there is index.

43
00:02:41,980 --> 00:02:44,270
Right now, we are exporting a function by default.

44
00:02:44,460 --> 00:02:50,120
Let's instead export a named function, it's going to export bonds to serve.

45
00:02:50,590 --> 00:02:52,720
Now it has just a very well defined name.

46
00:02:53,890 --> 00:02:59,410
Well, then apply some different arguments and annotations to our SERP command, so this will be called

47
00:02:59,410 --> 00:03:01,480
with a port that should be a no.

48
00:03:01,630 --> 00:03:04,780
Remember right now inside of our Seelie, the port we receive is a string.

49
00:03:04,990 --> 00:03:05,950
So we'll have to deal with that.

50
00:03:06,910 --> 00:03:13,690
We need to get a file name that's a string and then a directory where that file exists, which we'll

51
00:03:13,690 --> 00:03:14,760
abbreviate as Dir.

52
00:03:14,830 --> 00:03:16,300
And that will be a string as well.

53
00:03:18,480 --> 00:03:22,110
So then inside of our search function, again, for right now, we'll just do a console log and say.

54
00:03:23,480 --> 00:03:27,470
Serving traffic on port and they'll point out the port.

55
00:03:28,930 --> 00:03:30,490
I'll do another council log of.

56
00:03:31,840 --> 00:03:37,210
Saving fetching cells from and I'll print out the file name.

57
00:03:38,500 --> 00:03:45,230
And then finally, one last count log that just says something like that file is in directory Dir like

58
00:03:45,280 --> 00:03:45,550
so.

59
00:03:47,880 --> 00:03:53,880
All right, so let's say this will then go back over to our serve dots file, which is where a serve

60
00:03:53,880 --> 00:03:54,720
command is written out.

61
00:03:56,130 --> 00:04:00,360
So, again, inside of here, we're going to import that serve function we just put together and remember

62
00:04:00,360 --> 00:04:02,460
that's inside of our local API package.

63
00:04:03,030 --> 00:04:09,690
So to import it, we'll write out to import serve from and then the name of our local API package,

64
00:04:09,690 --> 00:04:12,690
which is simply local Dasch API.

65
00:04:15,870 --> 00:04:19,890
Then, rather than doing a simple console log right here, we will call surf.

66
00:04:21,110 --> 00:04:26,210
We'll provide the port, which is going to come out of that options object, so we'll provide options.

67
00:04:26,540 --> 00:04:27,050
Port.

68
00:04:29,920 --> 00:04:30,940
Then file name.

69
00:04:32,300 --> 00:04:36,830
And then a directory now we even really I said very briefly, oh, yeah, this directories where this

70
00:04:36,830 --> 00:04:40,970
file exists, we haven't really gone into that and how we're going to determine what the directory is.

71
00:04:40,970 --> 00:04:42,550
There's just a little gotcha around this.

72
00:04:42,560 --> 00:04:46,410
I just want you to be aware of whenever you're taking in file names from users at a silly.

73
00:04:46,730 --> 00:04:50,870
So right now I'm going to put in a directory of just forward slash like so and we'll come back to the

74
00:04:50,870 --> 00:04:56,000
next video and do a deeper explanation of what that directory argument is all about and why we are communicating

75
00:04:56,000 --> 00:04:56,480
it over.

76
00:04:57,590 --> 00:05:02,360
Now, last thing I want to point out here is that options export the options argument right here is

77
00:05:02,360 --> 00:05:03,880
technically typed as any.

78
00:05:04,250 --> 00:05:09,310
So options export is also of type any is actually, of course, as we saw, a string.

79
00:05:09,680 --> 00:05:13,070
So let's apply a manual type annotation to this options object.

80
00:05:13,460 --> 00:05:17,630
Make sure we mark port as being a string, will then get an air coming from typescript saying, hey,

81
00:05:17,630 --> 00:05:22,100
you're trying to provide a string when a number is required and that's where we will start to do it.

82
00:05:22,100 --> 00:05:23,690
Just a little bit of no parsing.

83
00:05:24,760 --> 00:05:29,710
So an options over here, I'm going to annotate this as an object that has a port property.

84
00:05:32,170 --> 00:05:33,610
That is going to be a string.

85
00:05:36,160 --> 00:05:40,900
So sure enough, we now get an air, we are told that we were providing a string when a number is expected

86
00:05:41,680 --> 00:05:45,550
to fix that up once again, we just do a very simple pass on it.

87
00:05:46,270 --> 00:05:47,920
We'll do a pass int.

88
00:05:52,210 --> 00:05:53,050
And that should be it.

89
00:05:54,890 --> 00:05:56,180
So once again, let's say this.

90
00:05:57,160 --> 00:05:58,300
Go back over to our terminal.

91
00:05:59,510 --> 00:06:05,690
And do another node index status, I'm going to run serv, I'm going to try to edit the books file and

92
00:06:05,690 --> 00:06:09,530
I'm going to run everything on PT. five thousand and again, of course, remember, I'm running this

93
00:06:09,530 --> 00:06:12,380
from the directory inside of my Seelie project.

94
00:06:12,960 --> 00:06:13,670
I'm going to run that.

95
00:06:14,180 --> 00:06:14,860
And there we go.

96
00:06:15,230 --> 00:06:17,120
So we get a very correct council log here.

97
00:06:17,300 --> 00:06:18,850
We're going to try to serve traffic report.

98
00:06:18,860 --> 00:06:22,910
Five thousand cells are going to be fetched and loaded from the bookcase file.

99
00:06:23,060 --> 00:06:25,970
And that file right now, again, just kind of a stand in right now.

100
00:06:26,940 --> 00:06:32,100
OK, so this looks good now the entire point of this video was to really just show you how you're communicating

101
00:06:32,100 --> 00:06:35,560
this information from our Seelie over to the local API.

102
00:06:35,880 --> 00:06:39,750
And the reason I'm kind of making a really big deal about this is that very quickly, you're going to

103
00:06:39,750 --> 00:06:44,130
start to realize that it kind of becomes a little bit kind of weird or murky.

104
00:06:44,430 --> 00:06:51,270
What amount of logic we place into this action function versus logic do we place inside of our Express

105
00:06:51,270 --> 00:06:52,230
API itself?

106
00:06:52,860 --> 00:06:57,270
It turns out that there's like a lot of different arguments or a lot of different work, different things

107
00:06:57,270 --> 00:07:02,820
we can calculate or figure out or stuff like that inside of our Seelie versus inside the Express package,

108
00:07:03,280 --> 00:07:07,200
for example, this entire discussion that we're about to have in just a moment around this directory

109
00:07:07,200 --> 00:07:12,360
argument, like I said, we need to provide or say, hey, here's the directory that the file that we're

110
00:07:12,360 --> 00:07:13,420
trying to edit is in.

111
00:07:13,920 --> 00:07:17,880
So at some point in time, we have to write out some code to figure out what directories the file name

112
00:07:17,880 --> 00:07:18,290
is in.

113
00:07:18,720 --> 00:07:23,130
And that, again, just very quickly becomes a question of, well, should we put the logic for that

114
00:07:23,130 --> 00:07:27,400
inside of our CLI or inside of our local API package?

115
00:07:28,260 --> 00:07:32,130
So, again, deciding what logic goes where just gets kind of a little bit weird.

116
00:07:32,130 --> 00:07:36,510
And that's why I'm just kind of making a little bit a big deal around exactly what is being provided

117
00:07:36,510 --> 00:07:38,940
from the Seelie over to the local API.

118
00:07:39,900 --> 00:07:43,860
OK, so enough this with all this in mind, Quickparts are going to come back the next video and discuss

119
00:07:43,860 --> 00:07:48,210
what the significance of this directory argument is right here and why we care about it at all.

