1 00:00:00,210 --> 00:00:04,890 In this video you're gonna use the callback pattern to improve the weather application. 2 00:00:04,920 --> 00:00:10,950 So in the last video we made a fake version of a geo code function which took in an address and a callback 3 00:00:10,980 --> 00:00:13,680 and I got you the data when it was available. 4 00:00:13,710 --> 00:00:17,390 Now we faked that by using set time out in this video. 5 00:00:17,400 --> 00:00:24,350 We're going to create a real version where we actually create a HDTV request inside of the function. 6 00:00:24,390 --> 00:00:26,370 Now what's that going to allow us to do. 7 00:00:26,730 --> 00:00:30,140 Well it's gonna allow us to do two very important things. 8 00:00:30,170 --> 00:00:36,420 One it's gonna make it easy to create code that is reusable and easy to maintain by having separate 9 00:00:36,420 --> 00:00:42,030 functions we can call we can run this code as many times as we need without copying it over and over 10 00:00:42,030 --> 00:00:45,830 again if I want to get the forecast in five different locations. 11 00:00:45,840 --> 00:00:52,170 I just call a function five times as opposed to needing to copy all of this code and logic. 12 00:00:52,170 --> 00:00:57,780 The other important thing is that it's going to make it much easier to do one thing before or after 13 00:00:57,780 --> 00:00:58,770 something else. 14 00:00:58,770 --> 00:01:04,920 So in this case we want to first geo code the address then I want to take the output the latitude and 15 00:01:04,920 --> 00:01:07,930 longitude and use that to fetch the weather. 16 00:01:08,040 --> 00:01:12,760 Now we could do this without creating our own functions but it would be pretty terrible. 17 00:01:12,810 --> 00:01:18,450 We can show you what that would look like by UN commenting all of the code up above copying it to the 18 00:01:18,450 --> 00:01:22,890 clipboard and pasting it in where it would be needed which is down here. 19 00:01:22,890 --> 00:01:29,280 So right after we get access to the latitude and longitude I could paste all of that code in and right 20 00:01:29,280 --> 00:01:29,700 away. 21 00:01:29,700 --> 00:01:31,590 It's just stressful to look at. 22 00:01:31,650 --> 00:01:37,230 Now if I was going to continue forward with this I would update that you are all over here concatenate 23 00:01:37,260 --> 00:01:40,340 ing on those variables and that would indeed work. 24 00:01:40,350 --> 00:01:42,500 There are a lot of problems with this code. 25 00:01:42,510 --> 00:01:45,450 First it's hard to read and maintain. 26 00:01:45,450 --> 00:01:52,080 Second it is deeply nested going up to six layers at some point which just makes code more complex than 27 00:01:52,080 --> 00:01:53,340 it needs to be. 28 00:01:53,340 --> 00:01:55,830 And third it's not reusable at all. 29 00:01:55,860 --> 00:02:00,990 If I want to fetch the weather somewhere else I can't because it's nested inside of all of this other 30 00:02:00,990 --> 00:02:01,820 code. 31 00:02:01,830 --> 00:02:07,560 In reality we're trying to perform two discrete actions so we should have two discrete functions we 32 00:02:07,560 --> 00:02:08,620 can use. 33 00:02:08,670 --> 00:02:10,860 I'm going to undo those changes I made. 34 00:02:10,860 --> 00:02:12,870 We're not going to go that route. 35 00:02:12,960 --> 00:02:16,460 We're going to undo them back to the point where we had at the beginning of the video. 36 00:02:16,470 --> 00:02:21,510 We have two separate requests which are currently not communicating with one another. 37 00:02:21,540 --> 00:02:24,520 Let's go ahead and fix that by creating our little functions. 38 00:02:24,540 --> 00:02:27,660 And together we're going to convert our geo coding example. 39 00:02:27,660 --> 00:02:32,340 Then as your challenge for the video you're going to end up doing the same for our weather. 40 00:02:32,340 --> 00:02:33,830 Request up above. 41 00:02:33,870 --> 00:02:39,300 Let's go ahead and get started by commenting out that weather request and we're actually also going 42 00:02:39,300 --> 00:02:43,780 to comment out our current geo coding request down below. 43 00:02:43,800 --> 00:02:45,170 We're going to do two things. 44 00:02:45,180 --> 00:02:49,300 We are going to define a function and we're going to call it. 45 00:02:49,350 --> 00:02:55,860 Let's start by creating a const geo code like we did in the other file though this time it's actually 46 00:02:55,980 --> 00:02:59,880 going to communicate with the map box API. 47 00:02:59,880 --> 00:03:01,740 Now we still need those arguments. 48 00:03:01,770 --> 00:03:02,920 So what's the input. 49 00:03:02,940 --> 00:03:04,470 What do we need to geo code. 50 00:03:04,680 --> 00:03:06,280 I need to know the address. 51 00:03:06,300 --> 00:03:09,800 So that's going to get taken in as the first argument. 52 00:03:10,080 --> 00:03:12,240 And the second is going to be the callback. 53 00:03:12,240 --> 00:03:14,190 This is the function we'll call. 54 00:03:14,190 --> 00:03:18,040 Once we have the latitude and longitude. 55 00:03:18,060 --> 00:03:21,450 Now from here we are indeed going to call geo code. 56 00:03:21,450 --> 00:03:25,440 So we're going to define this function which means we probably want to use it. 57 00:03:25,470 --> 00:03:29,880 Let's go ahead and add an example call in down below passing in an address. 58 00:03:29,880 --> 00:03:33,330 I'm going to use my current location Philadelphia. 59 00:03:33,330 --> 00:03:36,300 Then I'm going to pass in a callback as well. 60 00:03:36,300 --> 00:03:42,750 This is where we're gonna have access to the results after the geo coding process is complete when you're 61 00:03:42,750 --> 00:03:45,970 working with callback functions and the callback pattern. 62 00:03:45,990 --> 00:03:51,480 It's typical to see two arguments passed two callbacks and that's exactly what we're gonna do here. 63 00:03:51,480 --> 00:03:57,380 You either get an error if things went poorly or you get your data if things went well. 64 00:03:57,390 --> 00:04:02,850 Now this is not enforced but it is a common convention you're going to see across many different tools 65 00:04:02,850 --> 00:04:09,240 utilities and libraries including what we've already seen with request if things go poorly we get an 66 00:04:09,240 --> 00:04:11,800 error otherwise we get our response. 67 00:04:11,910 --> 00:04:18,570 Only one of these is ever going to have a value the other will be set to undefined allowing us to conditionally 68 00:04:18,570 --> 00:04:20,430 check what's going on. 69 00:04:20,430 --> 00:04:24,950 Now we have to actually make sure that callback gets called with the correct arguments. 70 00:04:24,990 --> 00:04:30,240 So let's go ahead and kick things off by making our request now up above. 71 00:04:30,240 --> 00:04:32,890 We already have that you are well in place. 72 00:04:33,000 --> 00:04:39,210 I'm gonna take the U.R.L. exactly as we have it up above not including those quotes and I'm going to 73 00:04:39,210 --> 00:04:41,120 copy it to the clipboard. 74 00:04:41,220 --> 00:04:46,650 So this is that you are all I should be able to paste in the browser to see the geo coding results for 75 00:04:46,650 --> 00:04:50,640 the current location which is statically defined as Philadelphia. 76 00:04:50,760 --> 00:04:56,730 I'm going to bring that down below and store it in a U RL variable so I'll create the variable I'll 77 00:04:56,730 --> 00:05:02,970 define the string and I'll paste the U.R.L. in now the entire you are rel is gonna be static except 78 00:05:02,970 --> 00:05:04,710 for this one piece right here. 79 00:05:04,710 --> 00:05:06,780 This is where the address goes. 80 00:05:06,910 --> 00:05:12,670 So I'm going to remove Philadelphia and I'm going to use the single quote twice. 81 00:05:12,670 --> 00:05:15,830 Then I'm going to use the plus operator right here. 82 00:05:15,900 --> 00:05:21,750 Now currently we're just taking the string beginning and the string end and putting them together right 83 00:05:21,750 --> 00:05:25,420 in between we want to put the address. 84 00:05:25,460 --> 00:05:29,380 So now we take the beginning of the U.R.L. then we have the address. 85 00:05:29,390 --> 00:05:35,030 Then we have the end of the you are well and now we're gonna make a request to whatever location is 86 00:05:35,030 --> 00:05:37,190 provided via that argument. 87 00:05:37,190 --> 00:05:42,230 So in this case it would be Philadelphia but I could change that to New York if I wanted to geo code 88 00:05:42,290 --> 00:05:44,650 somewhere else. 89 00:05:44,670 --> 00:05:48,090 This is Andrew from the future with a quick update to the line. 90 00:05:48,090 --> 00:05:51,690 We just wrote right here we have the before line. 91 00:05:51,690 --> 00:05:54,090 This is the line we just wrote together. 92 00:05:54,120 --> 00:06:00,760 We have the two parts of the U.R.L. are two strings and we can connect the address right in between. 93 00:06:00,900 --> 00:06:04,340 Down below under after we have the exact same thing. 94 00:06:04,380 --> 00:06:10,650 The only difference is what we're adding in between right here instead of just putting the address right 95 00:06:10,650 --> 00:06:15,840 into the string we're first passing the address through a function called ENCODE. 96 00:06:15,870 --> 00:06:22,440 You are a component now that function returns a string and that's going to get placed in the you are 97 00:06:22,440 --> 00:06:25,230 out now in almost all situations. 98 00:06:25,230 --> 00:06:30,750 You're not going to notice a difference when you run the project with these two different solutions. 99 00:06:30,750 --> 00:06:37,470 The only time you're really going to notice is if someone searches for a location that contains special 100 00:06:37,470 --> 00:06:42,110 characters that actually means something in a U structure. 101 00:06:42,300 --> 00:06:48,840 As an example if you were to use this code up above and search for a question mark the program would 102 00:06:48,840 --> 00:06:50,560 crash down below. 103 00:06:50,580 --> 00:06:57,240 When we encode those special characters the question mark becomes the encoded version which for this 104 00:06:57,240 --> 00:07:02,140 particular character is the percent sign then three capital F.. 105 00:07:02,250 --> 00:07:10,500 This is a safe U.R.L. map box is going to be able to get it decode it and handle the request correctly. 106 00:07:10,500 --> 00:07:16,470 So take just a quick moment to replace address with this function call right here then test out your 107 00:07:16,470 --> 00:07:19,800 code and make sure things still work as expected. 108 00:07:19,800 --> 00:07:27,130 All right let's jump back into the class now that we have a dynamic you are L based off of the arguments 109 00:07:27,130 --> 00:07:31,420 to the Geo code function let's actually fire off the request. 110 00:07:31,420 --> 00:07:37,420 I'll start by calling request passing in the options object as the first argument we are going to set 111 00:07:37,420 --> 00:07:37,680 up. 112 00:07:37,780 --> 00:07:39,020 You are all property. 113 00:07:39,130 --> 00:07:45,820 I have the value in the you RL variable and from there I'll also set up Jason as true making sure the 114 00:07:45,820 --> 00:07:47,980 data gets passed for us. 115 00:07:47,980 --> 00:07:54,820 Next up we do have to provide these second argument a function to run when the request completes. 116 00:07:54,820 --> 00:08:00,910 Right here I am going to provide my function like we've done with our two other request calls and like 117 00:08:00,910 --> 00:08:02,480 those calls for example. 118 00:08:02,500 --> 00:08:09,580 Right here we get access to error and to response and we're gonna use both of those down below. 119 00:08:09,580 --> 00:08:15,670 Now what's the next step the next step is to once again use an if statement to figure out exactly what 120 00:08:15,670 --> 00:08:16,180 happened. 121 00:08:16,180 --> 00:08:17,320 Did things go well. 122 00:08:17,320 --> 00:08:19,250 Did things go poorly. 123 00:08:19,270 --> 00:08:21,340 That's the next thing we have to do. 124 00:08:21,460 --> 00:08:26,990 So right here we're going to start with an if statement I am going to check if there is an error. 125 00:08:27,040 --> 00:08:30,380 If there is we are going to do something like we did before. 126 00:08:30,400 --> 00:08:34,480 Now the important piece to the puzzle is the actual message up above. 127 00:08:34,480 --> 00:08:38,620 We chose to log that message to the console now down below. 128 00:08:38,620 --> 00:08:42,000 The goal is to create a function that is highly reusable. 129 00:08:42,100 --> 00:08:47,500 When someone calls geo code they might want to do something different with the error message then log 130 00:08:47,500 --> 00:08:48,580 it to the console. 131 00:08:48,580 --> 00:08:55,570 Maybe they want to save it to a log file on the file system or send it to their sysadmin via an email. 132 00:08:55,570 --> 00:09:01,490 Those are all things you could do with the message and it's up to geo code to be as flexible as possible. 133 00:09:01,600 --> 00:09:06,470 So instead of logging out and the error we're going to pass it back to the callback the callback can 134 00:09:06,470 --> 00:09:07,880 then choose what to do. 135 00:09:07,930 --> 00:09:14,150 So I could call geo code five different times and do five different things with the error message. 136 00:09:14,170 --> 00:09:18,090 So right here inside of the if statement what are we going to do. 137 00:09:18,220 --> 00:09:22,840 We are going to call callback for the very first time in this function. 138 00:09:22,840 --> 00:09:26,620 Now we know that the callback function expects two arguments. 139 00:09:26,620 --> 00:09:28,810 We're gonna have an error if there is one. 140 00:09:28,810 --> 00:09:30,640 Otherwise we'll have data. 141 00:09:30,640 --> 00:09:32,940 Now in this case we do indeed have an error. 142 00:09:32,950 --> 00:09:39,190 So we are going to provide the first argument and we're gonna provide undefined as the value for the 143 00:09:39,190 --> 00:09:40,720 second right here. 144 00:09:40,750 --> 00:09:42,760 Let's go ahead and set up these string. 145 00:09:42,760 --> 00:09:46,980 So we are going to call the callback with a string for the first value. 146 00:09:46,990 --> 00:09:49,480 Now the first argument and the first one line up. 147 00:09:49,480 --> 00:09:53,680 So this is the error and we are going to say exactly what we said up above. 148 00:09:54,160 --> 00:09:58,940 Unable to connect to location services. 149 00:09:59,020 --> 00:10:00,020 Perfect. 150 00:10:00,040 --> 00:10:05,740 So now that message is getting sent back to the caller and they can choose to do whatever they want. 151 00:10:05,770 --> 00:10:09,160 Making geo code as flexible as possible. 152 00:10:09,160 --> 00:10:14,890 Now remember we don't want to provide a value for that second argument if we don't provide anything 153 00:10:14,890 --> 00:10:18,670 here undefined will be the value assigned by javascript. 154 00:10:18,790 --> 00:10:24,760 We could always be a bit more explicit setting up undefined though both solutions would be identical. 155 00:10:24,760 --> 00:10:27,520 So we've handled the if statement with the error. 156 00:10:27,520 --> 00:10:29,360 Now we're going to move on to the else. 157 00:10:29,380 --> 00:10:35,770 If so else if our condition and the code to run in this case we want to check if the features length 158 00:10:35,860 --> 00:10:40,250 is zero meaning that we didn't get any search results down below. 159 00:10:40,270 --> 00:10:41,660 Let's knock that out. 160 00:10:41,660 --> 00:10:42,640 So right here. 161 00:10:42,640 --> 00:10:49,000 Else if response dot body dot features dot length. 162 00:10:49,000 --> 00:10:54,360 So we're looking at the length of that array equals 0. 163 00:10:54,360 --> 00:10:56,520 If it does we have a problem. 164 00:10:56,580 --> 00:10:57,630 What are we going to do. 165 00:10:57,660 --> 00:10:59,400 We are going to call callback. 166 00:10:59,430 --> 00:11:02,760 So in this case we are also trying to report an error. 167 00:11:02,880 --> 00:11:08,990 So we're going to provide these string message as the first argument and undefined as the second what 168 00:11:09,000 --> 00:11:09,770 do we want to say. 169 00:11:09,780 --> 00:11:12,480 We'll say exactly what we said up above. 170 00:11:12,540 --> 00:11:15,740 Unable to find location. 171 00:11:15,800 --> 00:11:16,630 Period. 172 00:11:16,640 --> 00:11:19,100 Try another search. 173 00:11:19,100 --> 00:11:20,510 Excellent. 174 00:11:20,510 --> 00:11:25,320 So now that we have this in place we actually have error handling all set up. 175 00:11:25,370 --> 00:11:29,620 This callback would correctly get called if something went wrong with their request. 176 00:11:29,630 --> 00:11:35,150 Let's test our work before going any further inside of geo code just to make sure things work. 177 00:11:35,150 --> 00:11:41,330 We will choose to use console log but it's important to note that's a choice because we just get the 178 00:11:41,330 --> 00:11:42,530 rostering back. 179 00:11:42,530 --> 00:11:44,720 We could do whatever we want with it. 180 00:11:44,720 --> 00:11:50,960 Right here I am going to print error then as the second argument I'll print the actual error message 181 00:11:51,260 --> 00:11:53,840 and down below I'll do the same thing for data. 182 00:11:53,840 --> 00:11:57,260 Just making sure that we're always getting the results we expected. 183 00:11:57,260 --> 00:12:02,660 I'll call console dialogue with the data string then I'll actually print the data variable. 184 00:12:02,950 --> 00:12:08,360 Now to test things out we want to first do something like disable our internet connection and make sure 185 00:12:08,360 --> 00:12:14,840 we get that message so up above I am going to turn off my Wi-Fi and down below in the terminal. 186 00:12:14,840 --> 00:12:20,590 We have to get back over to the weather app directory so S.D. dot dot to get out of playground. 187 00:12:20,670 --> 00:12:21,790 Then forward slash. 188 00:12:21,790 --> 00:12:23,410 Weather hyphen app. 189 00:12:23,450 --> 00:12:27,350 Once I'm there I'm gonna use clear to clear the terminal output. 190 00:12:27,350 --> 00:12:32,710 Then I'll run the script node space app dot J s when I run it. 191 00:12:32,720 --> 00:12:34,490 What are we gonna get right here. 192 00:12:34,490 --> 00:12:41,720 I get as my error unable to connect to location services and as data I get undefined which is fantastic. 193 00:12:41,720 --> 00:12:44,720 That is exactly what we were looking for. 194 00:12:44,720 --> 00:12:50,300 Now let's go ahead and read enable our network connection and we're going to try with a location that's 195 00:12:50,300 --> 00:12:53,690 not going to return any matches down below. 196 00:12:53,690 --> 00:13:00,590 I'm going to swap out New York for something else like 12 what I'm going to save app dot J S I'm going 197 00:13:00,590 --> 00:13:03,860 to rerun the exact same command and what do I get. 198 00:13:03,860 --> 00:13:05,430 Unable to find location. 199 00:13:05,440 --> 00:13:07,180 Try another search. 200 00:13:07,490 --> 00:13:09,710 So all of our error handling is done. 201 00:13:09,710 --> 00:13:16,070 We can now move on to the easy part which is to set up the else clause and call the callback with the 202 00:13:16,070 --> 00:13:17,960 data that we want to expose. 203 00:13:17,990 --> 00:13:19,910 Now once again it's our choice. 204 00:13:19,910 --> 00:13:22,560 How much of what comes back on response. 205 00:13:22,580 --> 00:13:27,710 Do we want to share and the reality is we only want to share a couple of values. 206 00:13:27,770 --> 00:13:31,490 I'm gonna choose to share the latitude and longitude. 207 00:13:31,700 --> 00:13:34,960 And I'm also going to share one other value that came back. 208 00:13:35,060 --> 00:13:40,640 If I go back to the request in the browser I can swap it out with a real search. 209 00:13:40,760 --> 00:13:47,290 I'll the search for Philadelphia once again and these are the two values we're gonna start with. 210 00:13:47,530 --> 00:13:49,750 And I'm also going to include the place name. 211 00:13:49,750 --> 00:13:55,270 So when we print out the forecast we can include a more complete description of exactly where they're 212 00:13:55,270 --> 00:13:56,560 getting the weather for. 213 00:13:56,740 --> 00:14:00,520 All right let's go ahead and work on that by filling out else. 214 00:14:00,520 --> 00:14:06,220 Right here we are going to call the callback and I am going to provide to it two arguments. 215 00:14:06,220 --> 00:14:10,900 The first remember is where we would put the error but in this case we know there is none. 216 00:14:10,930 --> 00:14:14,250 So I am going to set that value equal to undefined. 217 00:14:14,350 --> 00:14:19,600 That's going to make sure that when the callback runs it does not have a value for error and it has 218 00:14:19,600 --> 00:14:20,770 a value for data. 219 00:14:21,280 --> 00:14:26,800 So the second argument I passed a callback that's going to be the data when things go well we're going 220 00:14:26,800 --> 00:14:34,180 to provide the caller the caller down below with those three values the latitude and longitude and we're 221 00:14:34,180 --> 00:14:37,990 going to provide them with a place name that label we just explored. 222 00:14:37,990 --> 00:14:42,420 Let's go ahead and knock all of that out using the exact same stuff we did up above. 223 00:14:42,430 --> 00:14:44,500 So first up we have latitude. 224 00:14:44,500 --> 00:14:47,680 I'll set that up as a property on this object. 225 00:14:47,680 --> 00:14:56,420 We know the value for that lives on response dot body dot features we're going to access the first item 226 00:14:56,450 --> 00:15:02,360 in that features array and then we're going to access the center property which is an array itself and 227 00:15:02,360 --> 00:15:07,280 we'll grab the first item from that which is exactly what we've already done up above. 228 00:15:07,280 --> 00:15:15,360 Next up we're going to add a another property onto here longitude this value is going to come from response 229 00:15:15,780 --> 00:15:23,100 dot body dot features grabbing the first one then dot center grabbing the second one. 230 00:15:23,130 --> 00:15:23,860 Perfect. 231 00:15:23,910 --> 00:15:26,790 This matches up with what we had up above. 232 00:15:26,790 --> 00:15:29,360 Next up we're going to add that other property. 233 00:15:29,400 --> 00:15:34,070 Now I could call this place name but I could also choose something that makes a bit more sense. 234 00:15:34,110 --> 00:15:36,760 I'll just have location right here. 235 00:15:36,930 --> 00:15:40,650 We are going to get that value from response dot body. 236 00:15:40,650 --> 00:15:42,810 We still need to go into that first feature. 237 00:15:42,810 --> 00:15:49,160 So dot features grabbing the first item from there we have the place name and property. 238 00:15:49,250 --> 00:15:54,150 So that would be dot place name dot place underscore name. 239 00:15:54,290 --> 00:15:55,310 Perfect. 240 00:15:55,310 --> 00:16:00,770 Now that we have this in place when things go well when the search returns results we are going to get 241 00:16:00,770 --> 00:16:03,680 that object sent back as the value for data. 242 00:16:04,010 --> 00:16:06,580 Let's go ahead and see if that actually happens. 243 00:16:06,650 --> 00:16:12,490 Right here I'm going to swap out 12 what with something else I'll choose to use my current location. 244 00:16:12,500 --> 00:16:13,760 Philadelphia. 245 00:16:13,760 --> 00:16:15,150 I'm gonna save the file. 246 00:16:15,230 --> 00:16:17,540 I'm going to rerun the script from down below. 247 00:16:17,540 --> 00:16:18,410 And what do I get. 248 00:16:18,410 --> 00:16:22,290 I get the latitude the longitude and the label showing up. 249 00:16:22,320 --> 00:16:27,760 Now if we wanted to change what we were searching for we could just update the geo code first argument. 250 00:16:27,770 --> 00:16:32,150 Right here there is a Philadelphia in New York as well though it's less popular. 251 00:16:32,150 --> 00:16:37,520 So I'm not going to get that back as the default result but if I do add new york on and I search for 252 00:16:37,520 --> 00:16:42,530 that I can now see the latitude and longitude for that city instead. 253 00:16:42,530 --> 00:16:49,220 Now we can easily call geo code more than one time to geo code from different places in our application. 254 00:16:49,250 --> 00:16:55,430 We have all of that sitting behind a single reusable function we can use as many times as we need. 255 00:16:55,430 --> 00:17:00,470 Let's wrap up by pulling that out into a separate file then we'll move on to the next video where you're 256 00:17:00,470 --> 00:17:03,350 going to do something similar for the forecast. 257 00:17:03,350 --> 00:17:10,010 I'm going to close all other files besides app dot J S I'm going to make a new directory over in weather 258 00:17:10,010 --> 00:17:16,160 app which I will call you tills and in there we're going to make a single file for now. 259 00:17:16,160 --> 00:17:19,520 So we will call this one something like geo code dot J. 260 00:17:19,520 --> 00:17:24,740 S and all we're going to do is take the function code from over here. 261 00:17:24,900 --> 00:17:29,730 We're going to remove it from Epcot J.S. cutting it out to the clipboard and we're going to paste it 262 00:17:29,910 --> 00:17:30,840 over here. 263 00:17:30,840 --> 00:17:33,150 Now I am going to have to require request. 264 00:17:33,150 --> 00:17:40,590 We'll do that real quick const request equals what comes back from calling require and passing in the 265 00:17:40,590 --> 00:17:42,720 module name then down below. 266 00:17:42,720 --> 00:17:43,910 We're going to export it. 267 00:17:44,010 --> 00:17:48,240 So module dot exports equals the geo code function. 268 00:17:48,510 --> 00:17:49,460 Perfect. 269 00:17:49,500 --> 00:17:55,500 Now this file's all done and we can easily require this anywhere we want to use it including an appetite 270 00:17:55,580 --> 00:17:55,970 and J. 271 00:17:55,970 --> 00:18:01,620 S Let's go ahead and wrap up by doing just that up above. 272 00:18:01,800 --> 00:18:08,460 We're going to grab the constant geo code from a call to require and since we're loading in a local 273 00:18:08,460 --> 00:18:11,160 file we start with DOT forward slash. 274 00:18:11,160 --> 00:18:17,250 From there we want to go into the utilize directory then forward slash the file name which is geo code. 275 00:18:17,250 --> 00:18:20,560 Once again leaving off the optional file extension. 276 00:18:20,580 --> 00:18:25,580 Now I'm going to save things I'm going to swap out the location for somewhere else. 277 00:18:25,620 --> 00:18:29,070 Let's go ahead and use something like Boston. 278 00:18:29,070 --> 00:18:34,350 I'll save the file I'll rerun the script and this is going to make sure that things are still working 279 00:18:34,530 --> 00:18:38,640 and right here we are getting the location information for Boston. 280 00:18:38,640 --> 00:18:39,690 Excellent. 281 00:18:39,690 --> 00:18:44,820 Now that we have all of this done for geo code it's going to be your job in the next video to do the 282 00:18:44,820 --> 00:18:47,250 same thing for our weather request. 283 00:18:47,280 --> 00:18:48,850 I'm excited to get to that. 284 00:18:48,870 --> 00:18:53,400 So let's go ahead and jump right into the next video where I'll show you what I'd like you to do.