1 00:00:00,420 --> 00:00:07,110 Welcome back. Let's expand on our Node knowledge from the previous video and actually create a script file 2 00:00:07,140 --> 00:00:08,210 that we can run. 3 00:00:08,270 --> 00:00:13,920 Let's just do the 'touch' command here again to create a file and we'll just call it 'script.js'. 4 00:00:14,850 --> 00:00:20,870 You'll see over here on the left-hand side that I have 'script.js' in my Node folder. 5 00:00:20,920 --> 00:00:24,110 Now within this folder I can now do anything in JavaScript. 6 00:00:24,130 --> 00:00:29,600 I can say 'const a = 5'. 7 00:00:29,770 --> 00:00:38,920 And that's not the folder that I want ... we want to open this and we'll say 'const a = 4' 8 00:00:38,920 --> 00:00:40,800 'const b = 5' 9 00:00:41,140 --> 00:00:50,780 And then we can just 'console.log(a + b)'. If I save this in order to run this script, 10 00:00:50,790 --> 00:00:55,400 all I do is 'node' and then the script name: 'script.js'. 11 00:00:55,480 --> 00:00:58,770 And because we're in the directory it'll know what 'script.js' is. 12 00:00:58,870 --> 00:01:02,420 And it'll give us 9. 13 00:01:02,460 --> 00:01:03,460 How cool is that? 14 00:01:03,490 --> 00:01:09,480 Now you also see that it exited; it didn't stay in the program, and that is because at the end of the 15 00:01:09,480 --> 00:01:12,840 file, once it reads everything and executes it 16 00:01:12,840 --> 00:01:21,620 – so the last thing it executes is 'console.log' – it runs 'process.exit' and exits out of the file. Let me show 17 00:01:21,620 --> 00:01:22,310 you something. 18 00:01:22,520 --> 00:01:33,040 If I did something called 'setTimeout', which we actually have in Node; if I do 19 00:01:33,370 --> 00:01:40,600 'node' 'global.setTimeout', I get a function. 20 00:01:40,630 --> 00:01:47,120 So if I do 'setTimeout', I can run a function again using our arrow functions. 21 00:01:48,750 --> 00:01:57,000 And within here I can do 'console.log()', and 'setTimeout' is cool because it allows you to say, "hey, when 22 00:01:57,060 --> 00:01:59,240 do you want this to be executed?" 23 00:01:59,370 --> 00:02:03,400 And that's the second parameter and I'll say 3 seconds. 24 00:02:03,420 --> 00:02:15,210 So if I save and I do 'node script.js' – one, two, three, and there you go: 9, and then 'process' exits 25 00:02:17,070 --> 00:02:19,180 Node is smart enough to run through this 26 00:02:19,200 --> 00:02:24,280 once this is done, ends the process and comes back to the Terminal. 27 00:02:24,510 --> 00:02:25,280 Very cool. 28 00:02:25,380 --> 00:02:30,000 And again within node we can actually use 29 00:02:32,770 --> 00:02:37,210 things that might be useful for us based on what global objects we have. 30 00:02:37,300 --> 00:02:45,000 For example one of the most popular ones are '__dirname' - if I save this and run 31 00:02:45,060 --> 00:02:45,510 'node script.js' ... 32 00:02:45,520 --> 00:02:47,530 I get my directory: 'node'. 33 00:02:50,480 --> 00:02:53,750 And I'll show you why that's useful when we start building a server. 34 00:02:54,710 --> 00:03:01,130 But as you can see, we have the power of the browser and running the scripts that we want right here 35 00:03:01,190 --> 00:03:02,650 in our Terminal. 36 00:03:02,660 --> 00:03:03,790 I'll see you in the next video, bye-bye.