1 00:00:00,330 --> 00:00:01,460 How did it go? 2 00:00:01,460 --> 00:00:02,410 Great job if you got it and 3 00:00:02,410 --> 00:00:05,000 it's okay if you didn't because I'll share my solution with you. 4 00:00:06,000 --> 00:00:10,460 First, we'll need to require the HTTPS module so that we can use our get request. 5 00:00:11,610 --> 00:00:15,768 We'll create a function named getDef that takes a term from the command line to 6 00:00:15,768 --> 00:00:18,420 search for from the Merriam Webster Dictionary. 7 00:00:20,090 --> 00:00:25,038 Now we'll create a request that uses the dictionary API url, 8 00:00:25,038 --> 00:00:30,000 including the term interpolated and ending with the API key. 9 00:00:31,860 --> 00:00:36,603 Now we'll take the response, and every time data comes in, 10 00:00:36,603 --> 00:00:40,790 we'll append the data to an empty string named body. 11 00:00:42,170 --> 00:00:46,950 Again, we'll use the .on method to do this to handle event listening and 12 00:00:46,950 --> 00:00:49,260 watching in node. 13 00:00:49,260 --> 00:00:52,100 And we'll wait for the end of the data using the end of it. 14 00:00:55,460 --> 00:01:00,075 When all the data has been sent, we'll use JSON parse to parse the data and 15 00:01:00,075 --> 00:01:03,810 we'll use the console log statement to print the data out. 16 00:01:05,070 --> 00:01:07,480 The response returned is in the form of an array. 17 00:01:08,490 --> 00:01:14,355 Our definition is in the first array item under a property name shortdef. 18 00:01:14,355 --> 00:01:16,365 This is what we'll print out to the screen. 19 00:01:18,297 --> 00:01:22,960 We'll add some error handling to watch out for errors on request, 20 00:01:22,960 --> 00:01:24,885 and catch parsing errors. 21 00:01:26,415 --> 00:01:30,969 Finally, we'll use argv to access our arguments, 22 00:01:30,969 --> 00:01:35,952 and call forEach on the command line arguments entered. 23 00:01:35,952 --> 00:01:36,950 We'll save. 24 00:01:38,700 --> 00:01:43,328 Go back to the terminal, we'll try node app.js imperative, 25 00:01:43,328 --> 00:01:47,520 and we get the short definition printed to the screen. 26 00:01:49,140 --> 00:01:50,841 We can try adding another word. 27 00:01:53,944 --> 00:01:55,410 And we get multiple definitions. 28 00:01:56,620 --> 00:01:57,820 Great work following along. 29 00:01:59,150 --> 00:02:01,960 You've created two command line node applications. 30 00:02:01,960 --> 00:02:04,240 And we've only scratched the surface of what node can do. 31 00:02:05,460 --> 00:02:10,045 With node, we can add open source code from other developers to our projects, 32 00:02:10,045 --> 00:02:13,881 build applications that scale, work with powerful libraries. 33 00:02:13,881 --> 00:02:17,570 And connect our front end projects to databases. 34 00:02:17,570 --> 00:02:18,810 There's so much more to learn.