1
00:00:01,620 --> 00:00:06,360
Let's go back over to our Ed, we're going to update our CLIA action function and make sure that we

2
00:00:06,360 --> 00:00:11,310
correctly calculate this directory and the file name, even if a user puts in some kind of relative

3
00:00:11,310 --> 00:00:12,510
path like this right here.

4
00:00:13,230 --> 00:00:17,370
OK, so back inside my editor, I'm going to first begin by going up to the top of the file and I'm

5
00:00:17,370 --> 00:00:19,850
going to import the path module from path.

6
00:00:20,370 --> 00:00:23,220
Remember, this is a part of the node standard library.

7
00:00:23,620 --> 00:00:28,530
There are a lot of functions inside that this path module that help us kind of calculate different paths

8
00:00:28,740 --> 00:00:29,880
on a file system.

9
00:00:30,790 --> 00:00:35,920
Then inside my action function, I'm going to zoom in just to make this easier to read, I'm going to

10
00:00:35,920 --> 00:00:41,140
do a console log and it's going to do a quick console logger to just to make sure we can only calculate

11
00:00:41,140 --> 00:00:43,230
the directory and the file names by themselves.

12
00:00:43,900 --> 00:00:48,250
So inside of this first console log, we are going to write out half join.

13
00:00:49,540 --> 00:00:52,820
We're going to join together, process dot c d.

14
00:00:54,410 --> 00:00:59,180
Asked her name, I'm going to pass inside their file name.

15
00:01:01,080 --> 00:01:02,580
Then as a second, councillor log.

16
00:01:03,910 --> 00:01:08,680
I'm going to add in half dot based name, file name.

17
00:01:10,820 --> 00:01:15,650
The first council log right here is how we are going to calculate that directory variable, this is

18
00:01:15,650 --> 00:01:19,890
going to take a look at what folder we are currently in inside of our terminal.

19
00:01:19,910 --> 00:01:26,000
So whenever a user runs that book, serve command process is going to return whatever directory the

20
00:01:26,000 --> 00:01:27,350
user ran that command from.

21
00:01:28,330 --> 00:01:31,030
Then Pattenden name is going to take a look.

22
00:01:31,970 --> 00:01:38,050
At whatever file a user provided, if the user provided just a normal file name, like, let's say notebook

23
00:01:38,480 --> 00:01:41,330
James, then we're going to get back an empty string.

24
00:01:41,930 --> 00:01:46,640
But if a user provides a sort of relative path like this right here, then we're going to instead get

25
00:01:46,640 --> 00:01:46,940
back.

26
00:01:47,150 --> 00:01:48,500
Just just notes.

27
00:01:49,440 --> 00:01:54,930
That's what this Durnan does, it gives us back just whatever folder is specified inside that string.

28
00:01:55,980 --> 00:01:59,730
The second consolation is that we're going to use to find the actual file name.

29
00:02:00,690 --> 00:02:05,990
So if a user gives us a relative path like this right here, base name will give us just the file name.

30
00:02:06,540 --> 00:02:13,260
And if a user gives us just a notebook, just like so, base name will also give us just notebook.

31
00:02:13,290 --> 00:02:13,800
James.

32
00:02:15,780 --> 00:02:19,800
Without a doubt, the easiest way to understand what's going on with all these different functions is

33
00:02:19,800 --> 00:02:20,850
to just run this code.

34
00:02:21,100 --> 00:02:23,070
So let's do that right now and see what happens.

35
00:02:23,430 --> 00:02:24,240
It's going to save this.

36
00:02:24,600 --> 00:02:25,950
I'm going to flip back over to my terminal.

37
00:02:26,840 --> 00:02:31,580
I'm again, inside of my directory, inside of our Seelie project, and I'll do a node.

38
00:02:33,010 --> 00:02:34,180
Index dogs.

39
00:02:35,910 --> 00:02:41,430
Serve and then for the hearth right here that we put in, we're not actually trying to look up any files

40
00:02:41,430 --> 00:02:45,450
or folders on the file system so we can put in absolutely any string here that we want.

41
00:02:45,750 --> 00:02:50,280
So we can imagine the inside of this directory, there is some kind of folder called maybe notes.

42
00:02:50,520 --> 00:02:53,940
Again, we're not going to actually look up that folder so we can just try to print out these different

43
00:02:53,940 --> 00:02:54,300
paths.

44
00:02:54,480 --> 00:02:56,010
Nothing is actually getting accessed.

45
00:02:56,700 --> 00:03:01,130
Then I'm going to imagine that maybe inside of this imaginary notes directory, there is a notebook

46
00:03:01,140 --> 00:03:01,800
JS file.

47
00:03:02,640 --> 00:03:06,240
It's going to run that and now I should see the absolute path.

48
00:03:07,170 --> 00:03:12,690
To this imaginary notes directory, and this is definitely the correct path for me, so I'm inside of

49
00:03:12,690 --> 00:03:13,500
a workspace folder.

50
00:03:13,500 --> 00:03:16,760
That's where I place all the different coding projects I have on my machine.

51
00:03:17,340 --> 00:03:22,170
I'm inside of a folder, which is where I'm putting all the code for this course as I'm writing it,

52
00:03:22,350 --> 00:03:24,390
the proper directory, just another folder inside there.

53
00:03:24,390 --> 00:03:27,210
And then here's our actual book project directory right here.

54
00:03:27,780 --> 00:03:29,430
So Seelie Dist Notes.

55
00:03:30,030 --> 00:03:31,170
So that is our directory.

56
00:03:31,170 --> 00:03:35,430
That is where we are trying to save some kind of note or JavaScript file to.

57
00:03:36,610 --> 00:03:42,310
And then we also quickly pulled off just the file name from this relative path, so I get back just

58
00:03:42,310 --> 00:03:43,660
notebook's.

59
00:03:44,720 --> 00:03:49,370
Now, a user can put in just about any kind of path in here, and it's always going to work as expected,

60
00:03:49,790 --> 00:03:55,280
and in theory, we're not going to try to create some kind of file called notes notebooks, which is

61
00:03:55,280 --> 00:03:57,440
what we really wanted to avoid in all scenarios.

62
00:03:59,040 --> 00:04:00,180
OK, it looks pretty good.

63
00:04:00,360 --> 00:04:03,000
So the last thing we're going to do is go back over to our Ed.

64
00:04:04,070 --> 00:04:09,050
Rather than doing a control log about these, we're going to instead assign them to variables and then

65
00:04:09,050 --> 00:04:11,780
pass or pass the result into our serve function.

66
00:04:12,920 --> 00:04:15,190
The first I can remove, the first consolo called.

67
00:04:16,269 --> 00:04:21,130
And then assign that to a variable that I will call Durch or for directory, and I'm going to pass that

68
00:04:21,130 --> 00:04:23,230
in as the third argument like so.

69
00:04:27,050 --> 00:04:32,780
Then I'm also going to assign or remove that second console function called in this case, because this

70
00:04:32,780 --> 00:04:37,040
is a very short little function called right here, rather than assigning the result to another variable.

71
00:04:37,220 --> 00:04:39,860
I'm just going to pass that in directly to our second argument.

72
00:04:40,400 --> 00:04:42,290
I'm going to take the path based name.

73
00:04:43,330 --> 00:04:46,030
But it and then put it in as that second argument.

74
00:04:48,020 --> 00:04:48,890
And that should be it.

75
00:04:50,390 --> 00:04:54,530
It's going to save that and then one last test, the back inside my terminal, I'm going to try running

76
00:04:54,530 --> 00:04:55,520
that same command again.

77
00:04:55,810 --> 00:05:00,460
We should see the correct control logs coming out of our local Clie application now.

78
00:05:00,950 --> 00:05:03,310
So here's from our local Seelie app.

79
00:05:03,830 --> 00:05:10,250
I see that we are trying to save and fetch cells from the notebook's file and that file is in this directory.

80
00:05:10,970 --> 00:05:15,170
I should also be able to repeat something very similar, but without any kind of a relative directory

81
00:05:15,170 --> 00:05:15,550
on it.

82
00:05:15,920 --> 00:05:22,470
So if I do just notebook's I see notebook details and that file is inside of this directory.

83
00:05:23,060 --> 00:05:23,410
All right.

84
00:05:23,420 --> 00:05:24,500
That definitely looks good to me.

85
00:05:25,610 --> 00:05:26,960
All right, so this is fantastic.

86
00:05:26,990 --> 00:05:29,170
Let's take a pause right here and continue in just a moment.

