1
00:00:00,420 --> 00:00:01,010
Nice.

2
00:00:01,080 --> 00:00:07,200
Now we know how we can work with Path module, and like I mentioned in the previous video, we also

3
00:00:07,200 --> 00:00:11,080
have an option of interacting with a file system.

4
00:00:11,610 --> 00:00:15,870
So what I would want right now is first creating file.

5
00:00:15,870 --> 00:00:21,200
I'll call this nine and say path and module.

6
00:00:21,600 --> 00:00:27,980
So just grab everything that I have and just copy and paste.

7
00:00:28,380 --> 00:00:36,120
And once we have this one out of the way, I'll just remove and keep the objets clean for now as well

8
00:00:36,120 --> 00:00:37,400
as clearly console.

9
00:00:37,920 --> 00:00:42,570
And yes, we have an option of interacting with the file system on the module.

10
00:00:42,880 --> 00:00:51,110
The name of the module is now essentially there are two flavors when it comes to file module.

11
00:00:51,450 --> 00:00:57,360
We can do it asynchronously non blocking or we can do it synchronously, which is going to be blocking,

12
00:00:57,630 --> 00:01:02,160
but for the time being will just cover both of the setups.

13
00:01:02,790 --> 00:01:09,840
And then later on, of course, we will cover what are the differences and why you should prefer one

14
00:01:09,840 --> 00:01:11,700
over the other one for now.

15
00:01:11,940 --> 00:01:17,040
Just think of them as different methods, but eventually, yes, we'll talk about it.

16
00:01:17,430 --> 00:01:18,900
The whole structure of the node.

17
00:01:19,750 --> 00:01:26,350
And why would you want to use the non blocking code instead, as well as different approaches when it

18
00:01:26,350 --> 00:01:27,970
comes to your callback functions?

19
00:01:28,000 --> 00:01:29,820
Different solutions for now.

20
00:01:29,820 --> 00:01:35,440
I just want to show you both methods, essentially for methods, and then we'll just move on to the

21
00:01:35,440 --> 00:01:36,070
next topic.

22
00:01:36,520 --> 00:01:41,590
And in order to set this up, in this case, I'm just going to the structure right away, the methods

23
00:01:41,590 --> 00:01:42,310
that I'm looking for.

24
00:01:42,520 --> 00:01:45,550
And in the first video, we'll take a look at the synchronous ones.

25
00:01:45,770 --> 00:01:53,590
So that's why all the structure read, file and sync, and that is coming from require and the module

26
00:01:53,590 --> 00:01:56,170
name is effervesce again.

27
00:01:56,170 --> 00:02:00,580
Please keep in mind it will be the same thing if I were to.

28
00:02:01,510 --> 00:02:09,850
Go like this fast and then fast and whatever name I was going to read, file Senk and of course I have

29
00:02:09,850 --> 00:02:10,419
access to it.

30
00:02:10,750 --> 00:02:13,630
I'm just showing you a different way how we can access those methods.

31
00:02:13,900 --> 00:02:20,290
We just structure them out of the first module and then the second one will be right.

32
00:02:20,290 --> 00:02:21,070
File sync.

33
00:02:22,050 --> 00:02:28,080
All right, file, thank once I have the structured, both of them, then I'm going to set up two variables.

34
00:02:28,380 --> 00:02:32,760
So first, we'll read two files we have and create those files yet.

35
00:02:32,760 --> 00:02:34,290
But in a second we will.

36
00:02:34,530 --> 00:02:38,810
And then eventually we'll create a new file with right files.

37
00:02:39,450 --> 00:02:41,850
So I would want you to go to the content folder.

38
00:02:41,850 --> 00:02:44,700
If you haven't created, then I suggest creating one.

39
00:02:45,000 --> 00:02:50,090
I'll keep the folder just because I believe the path module is still using it.

40
00:02:50,490 --> 00:02:53,610
But in a content, I'll create a new file.

41
00:02:53,620 --> 00:02:57,530
So not in a subfolder, but actually in the content.

42
00:02:57,870 --> 00:03:02,160
I'll say first, first and then the next day.

43
00:03:02,520 --> 00:03:04,760
So this, by the way, sets it up in a content.

44
00:03:04,770 --> 00:03:06,540
So let me move it up or I'm sorry.

45
00:03:06,540 --> 00:03:11,340
This is set up in a subfolder, I believe, and it tells me, do I want to move?

46
00:03:11,340 --> 00:03:12,570
Yes, I would like to move.

47
00:03:12,780 --> 00:03:14,730
And now I have the content.

48
00:03:15,270 --> 00:03:19,210
But as the first texta and then I have the subfolder with testi.

49
00:03:19,920 --> 00:03:23,100
Of course if you want you can place it in a folder that's really up to you.

50
00:03:23,370 --> 00:03:26,220
But in my case, I would want them simply in a content.

51
00:03:26,490 --> 00:03:30,000
So I'll go the second one to the end.

52
00:03:30,000 --> 00:03:32,880
As far as the values, I'll say hello.

53
00:03:33,330 --> 00:03:34,830
This is first.

54
00:03:35,820 --> 00:03:43,150
First text file and I can copy and paste the value and just change it around to the second file.

55
00:03:43,440 --> 00:03:50,550
So in the second text, we'll say second text file once we have both the text files.

56
00:03:50,790 --> 00:03:54,000
Now, let's take a look at how we can read from the file system.

57
00:03:54,450 --> 00:03:58,890
And since we have read File Sync, we know it as a method.

58
00:03:59,130 --> 00:04:02,340
And in that method, we need to provide two parameters.

59
00:04:02,610 --> 00:04:08,370
We need to provide a path to that specific file as well as well.

60
00:04:08,400 --> 00:04:11,970
What is the encoding so the node knows how to decode file?

61
00:04:12,360 --> 00:04:17,279
Generally you'll go with UTF eight will first go with first.

62
00:04:17,310 --> 00:04:18,250
That's my variable.

63
00:04:18,250 --> 00:04:20,790
Will go with read file sync.

64
00:04:21,640 --> 00:04:27,910
My method and like I said, we provide a path, we go to the content, and then instead of the content,

65
00:04:27,910 --> 00:04:29,920
there's going to be a first.

66
00:04:31,760 --> 00:04:39,080
And then as far as the encoding of default, one will be UTF eight, but if you want to be a bit specific,

67
00:04:39,320 --> 00:04:45,770
just set up the second parameter and notice these are all your options and just go with your putrefied.

68
00:04:46,440 --> 00:04:50,000
OK, once we have everything in place, we can copy and paste.

69
00:04:50,300 --> 00:04:52,310
This is going to be the value for the second one.

70
00:04:52,790 --> 00:04:54,960
And we just need to change the file now.

71
00:04:55,000 --> 00:05:01,160
So we have the second one and now in a console log, we should see both of the text.

72
00:05:01,560 --> 00:05:11,240
So if I go with console first and then second, I should have one long text and let's go with Node and

73
00:05:11,240 --> 00:05:12,890
I just want to have both of them.

74
00:05:12,890 --> 00:05:18,080
Why don't we create a new file and the method for that is right.

75
00:05:18,230 --> 00:05:19,870
File sync the way it works.

76
00:05:19,880 --> 00:05:23,090
Again, we provide two values, two arguments.

77
00:05:23,420 --> 00:05:25,040
One is going to be the file name.

78
00:05:25,280 --> 00:05:31,310
And if the file is not there, then Node will create that file and you'll see that in a second.

79
00:05:31,490 --> 00:05:34,610
And the second one is the value that we would want to pass.

80
00:05:35,030 --> 00:05:38,990
And I'm going to go with Right File Sync, Right file sync.

81
00:05:39,290 --> 00:05:44,330
And like I said, first is going to be a path so you can call this third, you can call this result

82
00:05:44,330 --> 00:05:45,340
whatever you want.

83
00:05:45,620 --> 00:05:53,210
In my case, I'm going to go with forward slash content and then we're looking for a result sync and

84
00:05:53,210 --> 00:05:54,470
this is going to be texte.

85
00:05:54,740 --> 00:05:57,890
And then as far as the value, if you want, you can simply pascoal the world.

86
00:05:58,010 --> 00:05:58,700
And that's that.

87
00:05:58,910 --> 00:06:03,350
In my case, I'm going to make it a bit more interesting where we'll set up a template string.

88
00:06:03,920 --> 00:06:05,600
So here is the result.

89
00:06:06,470 --> 00:06:14,360
And why don't we use the interpellation, I say first and second, so we'll have first value and then

90
00:06:14,360 --> 00:06:15,060
the second one.

91
00:06:15,440 --> 00:06:18,700
And, you know, why don't we add here, Colin as well?

92
00:06:18,920 --> 00:06:25,140
So let's say first and then let's place a comma and then we're going to go with second.

93
00:06:25,700 --> 00:06:31,280
Then if the file is not there, then of course, no, we'll create one.

94
00:06:31,640 --> 00:06:39,070
And if the file is already there, node by default, we'll override all the values that are in the file.

95
00:06:39,080 --> 00:06:40,910
And I'll show you that in a second.

96
00:06:41,150 --> 00:06:45,680
So I'm going to go here with node and jazz and check it out.

97
00:06:45,930 --> 00:06:48,830
Now I have a result sink.

98
00:06:49,940 --> 00:06:56,180
And then inside that I have here is the result, although this is first text file and also half.

99
00:06:56,180 --> 00:07:01,760
Hello, this is second text file and just the shock showcase that if there are some values, they will

100
00:07:01,760 --> 00:07:03,540
be overridden by node.

101
00:07:04,070 --> 00:07:12,950
Well, if I go with a simple hello world and then I run node objets, can I have my new result now if

102
00:07:12,950 --> 00:07:15,050
you just want to open to the file?

103
00:07:15,530 --> 00:07:18,020
Well, we need to pass in one more argument.

104
00:07:18,340 --> 00:07:19,670
Notice I have the first one.

105
00:07:19,670 --> 00:07:23,270
I have the value that I would like to set up in a file.

106
00:07:23,510 --> 00:07:27,200
And the third one is an object, basically an options object.

107
00:07:27,410 --> 00:07:30,050
And here the property name is a flag.

108
00:07:30,470 --> 00:07:36,170
And if you'll set this flag equal to a node, will open this.

109
00:07:36,170 --> 00:07:41,090
And the easiest way for me to show that is here on node objets.

110
00:07:41,330 --> 00:07:43,430
And now we should have two results.

111
00:07:43,680 --> 00:07:45,110
So we have here is the result.

112
00:07:45,290 --> 00:07:47,930
And notice now we're starting a new line.

113
00:07:48,230 --> 00:07:48,580
Why?

114
00:07:48,700 --> 00:07:51,500
Well, because by default, we are overriding everything.

115
00:07:51,710 --> 00:07:56,300
And then when we add that flag, then, of course, we create a new value.

116
00:07:56,630 --> 00:08:03,530
So these are two very useful methods that we can use with node to read files as well as create ones

117
00:08:03,530 --> 00:08:04,330
from scratch.

