1
00:00:00,210 --> 00:00:07,050
Since they know we can interact with the filesystem, something we couldn't do when we used our JavaScript

2
00:00:07,050 --> 00:00:07,630
in a browser.

3
00:00:07,980 --> 00:00:15,030
Another useful module is a path module which allows us to interact with file path easily.

4
00:00:15,570 --> 00:00:23,880
And I'm going to remove all my code in the app just because since I created a file by the name of eight

5
00:00:24,180 --> 00:00:32,400
OS and module and of course copy and pasted the contents from the previous video, that's why the objects

6
00:00:32,400 --> 00:00:36,030
or remove everything and the setup is going to be exactly the same.

7
00:00:36,030 --> 00:00:37,510
We come up with some kind of name.

8
00:00:37,890 --> 00:00:43,140
Now most likely it's going to be path and then we pass in the module we would want to get.

9
00:00:43,500 --> 00:00:46,320
And this case, of course, it is a path module.

10
00:00:46,860 --> 00:00:50,100
And then let's just start with a very useful property.

11
00:00:50,980 --> 00:00:56,490
A separate property that returns a platform specific separator.

12
00:00:56,950 --> 00:01:06,230
So if I go straight up with a log and then path setup, this is going to turn my platform specific separator.

13
00:01:06,490 --> 00:01:12,970
So if I write no address, I have for now, if you're using a different platform for you, the value

14
00:01:12,970 --> 00:01:14,090
might be different.

15
00:01:14,350 --> 00:01:17,560
After that, let's take a look at the path that join.

16
00:01:17,770 --> 00:01:25,660
So the join method, which joins a sequence of path segments using that platform specific separator

17
00:01:25,930 --> 00:01:27,000
as the limiter.

18
00:01:27,340 --> 00:01:32,410
And second thing it does, it returns a normalized resulting path.

19
00:01:32,770 --> 00:01:37,600
In order to show an example, I'll create a new folder, not a new file, but a new folder.

20
00:01:37,900 --> 00:01:43,960
I'll zoom in and I'll say content and inside of this content folder and create another one.

21
00:01:44,260 --> 00:01:47,110
And I'll simply call this generic subfolder.

22
00:01:47,410 --> 00:01:54,020
And in this subfolder, I'll say a test and text file instead of the text file.

23
00:01:54,340 --> 00:01:56,410
I mean, you can play something.

24
00:01:56,560 --> 00:01:58,450
You can admit it doesn't really matter.

25
00:01:58,630 --> 00:02:06,430
I'll just say text and then the next day and once we say it back in the address now I want to use that

26
00:02:06,670 --> 00:02:14,740
path, that joint method, several seconds and then file path is equal to path that joined.

27
00:02:15,010 --> 00:02:18,820
And then we need to pass in those values as strings.

28
00:02:19,140 --> 00:02:22,450
So, for example, since I'm looking for the content folder.

29
00:02:23,320 --> 00:02:30,580
I'll simply say forward slash and burn content, then I know that inside of the content folder, I have

30
00:02:30,580 --> 00:02:37,380
the folder, that's another folder, and then eventually there's going to be a test the see.

31
00:02:37,720 --> 00:02:40,770
So we'll go test and then dot the city.

32
00:02:41,050 --> 00:02:42,250
We save the sucker.

33
00:02:42,520 --> 00:02:48,250
And then if we'll console lock the file path, we should see the whole path.

34
00:02:48,430 --> 00:02:51,600
It is normalized and we'll get it as a value.

35
00:02:51,790 --> 00:02:55,530
So we have content subfolder first and the next day.

36
00:02:55,810 --> 00:03:01,810
So if I start adding some type of forward Slasher's, meaning trailing Slasher's, they will be removed.

37
00:03:02,250 --> 00:03:07,530
We still get the normalized path and we can also get the base name.

38
00:03:07,780 --> 00:03:14,820
So for example, I create this file path, but I only would want the last portion of it.

39
00:03:15,010 --> 00:03:18,940
I can access it while the method name is Bergenheim name.

40
00:03:19,390 --> 00:03:27,910
So we're going to go with Const and Basch and Path, that based name, and we just pass in that file

41
00:03:27,910 --> 00:03:33,150
path and now if we cancel out the base we should see the text again.

42
00:03:33,490 --> 00:03:34,690
These are just some of it.

43
00:03:34,690 --> 00:03:41,380
If you want just a directory, of course you can imagine that there is a method that returns that as

44
00:03:41,380 --> 00:03:41,560
well.

45
00:03:41,570 --> 00:03:45,760
But since I don't want to cover each and every method, that's why I will skip that one.

46
00:03:46,120 --> 00:03:53,500
And there is not only I see my normalized path, but I also see the test the next day, which is my

47
00:03:53,500 --> 00:03:53,800
base.

48
00:03:54,190 --> 00:03:59,230
And the last method that I would want to showcase is path that resolve and why it's so cool, because

49
00:03:59,230 --> 00:04:05,530
returns an absolute path and once in one of our applications, we need to provide that absolute path.

50
00:04:05,720 --> 00:04:08,350
That's why, of course, we'll have to use that method.

51
00:04:08,830 --> 00:04:16,380
And when it comes to paths that resolve, it accepts a sequence of path or path segments and resolves

52
00:04:16,390 --> 00:04:18,380
it into an absolute path.

53
00:04:18,700 --> 00:04:25,690
So below the base, I'm going to go with cons and then absolute No one is equal to path and we're looking

54
00:04:25,690 --> 00:04:27,460
for that resolve.

55
00:04:27,880 --> 00:04:33,940
And here remember when we talked about the globalist, one of the first Globalstar I covered was underscore

56
00:04:33,940 --> 00:04:35,100
underscore Durnan.

57
00:04:35,530 --> 00:04:40,960
So this is going to point to this directory where the abcess is located.

58
00:04:41,410 --> 00:04:45,460
And once we're here, we just need to provide rest of the values.

59
00:04:45,970 --> 00:04:51,130
In my case, that is content that I'm looking for sub folder.

60
00:04:51,460 --> 00:04:58,750
And then eventually I would want to get to the test the to want to get this absolute path.

61
00:04:58,990 --> 00:05:07,660
And then once I set up the value, if I go with my control log and if I provide absolute once I run

62
00:05:07,660 --> 00:05:16,270
node and objects and probably guess that in the console, I'll have my absolute path to the test.

63
00:05:17,080 --> 00:05:19,970
And if you're wondering why we would ever want that.

64
00:05:20,000 --> 00:05:26,230
Well, remember, our application is going to run in different environments.

65
00:05:26,230 --> 00:05:26,530
Right?

66
00:05:26,930 --> 00:05:34,150
So, of course, the path to some kind of resource is going to be different in my computer, in my local

67
00:05:34,150 --> 00:05:37,470
machine than, for example, in Morocco.

68
00:05:38,170 --> 00:05:43,690
Hopefully it is clear and I can take a look at the next useful built in module.

