1 00:00:00,850 --> 00:00:03,552 Who says back-end programs can't be interactive? 2 00:00:03,552 --> 00:00:08,032 In this program, we'll learn different ways to give input and output with Node. 3 00:00:08,032 --> 00:00:10,892 One way we can do this is by using the REPL. 4 00:00:10,892 --> 00:00:13,885 This stands for read-evaluate-print loop. 5 00:00:13,885 --> 00:00:18,412 The REPL is an interactive programming environment that can read our input, 6 00:00:18,412 --> 00:00:24,230 evaluate its meaning, print out feedback, and loop over this process as needed. 7 00:00:24,230 --> 00:00:27,910 Node can function as a REPL with a single command. 8 00:00:27,910 --> 00:00:32,907 Node is terminal based, so open up your terminal to try out the Node REPL. 9 00:00:32,907 --> 00:00:36,946 If you're using workspaces, Node will already be installed. 10 00:00:36,946 --> 00:00:41,870 We'll type Node, a caret or greater than symbol should appear. 11 00:00:41,870 --> 00:00:46,630 And now you can write JavaScript code that Node will interpret and respond to. 12 00:00:46,630 --> 00:00:49,670 Remember, JavaScript has the ability to do math. 13 00:00:49,670 --> 00:00:52,850 We can enter an equation in the REPL and get our answer. 14 00:00:53,850 --> 00:00:55,240 Let's try something really hard. 15 00:00:57,198 --> 00:01:02,548 2 + 2, Node already knows that the answer is 4. 16 00:01:02,548 --> 00:01:04,604 We can also define variables. 17 00:01:04,604 --> 00:01:08,844 Use let favoriteMovie, 18 00:01:08,844 --> 00:01:13,767 make sure I use proper camelCase, 19 00:01:19,961 --> 00:01:23,210 I'm gonna type in favoriteMovie again, I get the value 'lionKing'. 20 00:01:24,900 --> 00:01:26,980 We don't have a DOM to work with. 21 00:01:26,980 --> 00:01:28,520 But remember those host objects. 22 00:01:29,660 --> 00:01:33,480 Node has host objects including its own version of the console object. 23 00:01:34,530 --> 00:01:44,112 We can console.log, our favorite movie variable, 24 00:01:44,112 --> 00:01:49,524 and it prints out the value lionKing to the console or terminal. 25 00:01:49,524 --> 00:01:53,893 Input and output like this shows us some of the capabilities of Node. 26 00:01:53,893 --> 00:01:58,877 But one thing that makes Node great is its ability to run programs in JavaScript files. 28 00:01:59,413 --> 00:02:04,199 With Node we can execute a program using the node command followed by the name of 29 00:02:04,199 --> 00:02:05,080 the program. 30 00:02:06,090 --> 00:02:11,187 Let's create a directory with the mkdir keyword. 31 00:02:13,274 --> 00:02:20,248 And we should probably first exit the REPL, by pressing Ctrl + C twice. 32 00:02:24,011 --> 00:02:31,708 Now again, we'll create a directory named nodePractice. 33 00:02:31,708 --> 00:02:33,612 Change into that directory. 34 00:02:38,817 --> 00:02:43,260 And we'll open up visual studio code to start writing our files. 35 00:02:43,260 --> 00:02:48,907 We'll create an app.js file. 36 00:02:48,907 --> 00:02:54,487 And inside the file, we'll type console.log. 37 00:02:58,032 --> 00:03:03,365 Our favorite programming phrase, ("Hello World") and save. 38 00:03:05,109 --> 00:03:10,057 Back in the console, you can type node app.js, 39 00:03:10,057 --> 00:03:15,670 and Hello World is printed out to the console. 40 00:03:15,670 --> 00:03:18,810 Node can do a lot more than just print messages to the screen. 41 00:03:18,810 --> 00:03:22,222 You've just learned two ways we can use Node to work with JavaScript outside of 42 00:03:22,222 --> 00:03:23,330 the browser. 43 00:03:23,330 --> 00:03:26,930 And this is a tiny sample of what Node is capable of doing. 44 00:03:26,930 --> 00:03:29,990 We'll learn about more tasks like connecting to an API, and 45 00:03:29,990 --> 00:03:32,570 retrieving useful information in the next steps.