-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9. Working with the REPL vs Using Files.srt
151 lines (114 loc) · 3.91 KB
/
9. Working with the REPL vs Using Files.srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
1
00:00:02,230 --> 00:00:08,750
Now before we finally dive into the javascript refresher or optionally in case you skip that, into the
2
00:00:08,810 --> 00:00:10,010
nodejs basics,
3
00:00:10,220 --> 00:00:17,180
let me dive into two different ways of executing your node code. One way of executing it which I briefly
4
00:00:17,180 --> 00:00:25,700
mentioned earlier in this module is the repl. Repl stands for read, reading user input, eval, evaluating
5
00:00:25,700 --> 00:00:35,390
user input, print, outputting a result and l, loop for returning and waiting for new input and the repl
6
00:00:35,390 --> 00:00:36,380
is what you use
7
00:00:36,440 --> 00:00:43,040
if you just type node into your terminal. Here I am in the terminal or on Windows this would be your command
8
00:00:43,040 --> 00:00:48,950
prompt and there if you just type node with node installed, you are now in the repl which you can identify
9
00:00:48,950 --> 00:00:54,350
by the fact that you now don't have that full path of your computer name at the beginning but just that
10
00:00:55,010 --> 00:00:56,340
greater than sign
11
00:00:56,480 --> 00:01:05,090
and there you can execute node commands like console log, two plus two or also writing, interacting with
12
00:01:05,090 --> 00:01:05,750
files.
13
00:01:05,810 --> 00:01:12,860
You can import the file system there just as we did it previously in our file and then we can use that
14
00:01:12,890 --> 00:01:15,760
to write a file synchronously and so on,
15
00:01:15,860 --> 00:01:17,340
so that will all work here
16
00:01:17,570 --> 00:01:21,870
and this is of course an environment where we don't store our code in files
17
00:01:21,920 --> 00:01:25,890
but we write our node application with every line.
18
00:01:25,940 --> 00:01:28,150
The lines don't work independent from each other,
19
00:01:28,190 --> 00:01:31,730
so I can now use the file system package for example
20
00:01:31,730 --> 00:01:39,710
now that I imported it one line earlier but once I quit out of this process with control c, I'm done.
21
00:01:39,710 --> 00:01:41,090
This is not saved anywhere,
22
00:01:41,090 --> 00:01:45,950
this is not a file I can execute again and this therefore is a great playground.
23
00:01:45,950 --> 00:01:51,470
The alternative to running codes is that you execute files as we did it before and as we will basically
24
00:01:51,470 --> 00:01:53,250
do it for the rest of the course,
25
00:01:53,260 --> 00:01:56,900
this is the alternative to using the repl. When you execute files,
26
00:01:56,900 --> 00:02:02,750
the advantage of course is and that is why we use it for real apps, that we write our code in advance
27
00:02:02,750 --> 00:02:08,930
and we can always execute it and when we build a real app, we want to save our code of course in files
28
00:02:08,930 --> 00:02:14,120
which we can then deploy in the end which we could share with other developers and where we can also pause
29
00:02:14,120 --> 00:02:15,840
our work and pick up later
30
00:02:15,880 --> 00:02:22,060
and where we never lose the code we write. But the repl is a great playground because we can use that to run some
31
00:02:22,070 --> 00:02:27,660
commands, to try out certain things because we execute code as we write it and therefore these are the
32
00:02:27,710 --> 00:02:30,650
two ways of running your node code,
33
00:02:30,800 --> 00:02:35,390
obviously we'll go with the store code in files approach in this course
34
00:02:35,480 --> 00:02:41,750
but whenever I say repl, I'm referring to this direct input way which I can recommend for trying out
35
00:02:41,750 --> 00:02:45,710
some features but not for writing real applications,
36
00:02:45,710 --> 00:02:47,510
that is not what you would do.
37
00:02:47,510 --> 00:02:50,430
I just wanted to get these two ways out of the way,
38
00:02:50,480 --> 00:02:56,270
we'll focus on the left one here and with that, let's dive into writing some code with the next modules.