1
00:00:01,110 --> 00:00:05,010
Now we've got our project all set up and ready to go, we can start to actually write out some code.

2
00:00:05,340 --> 00:00:10,650
So to get started, I'm going to create a new file inside of my project directory called Index Dots.

3
00:00:11,310 --> 00:00:17,220
Notice the file extension on here is it's a start for as you might guess, TypeScript, we're always

4
00:00:17,220 --> 00:00:20,370
going to place all of our typescript code into DOT files.

5
00:00:21,270 --> 00:00:25,110
So now inside this file, we can start to actually write out some code to implement our program.

6
00:00:25,380 --> 00:00:30,870
And just as a quick reminder, our goal here is to fetch some JSON data and print the results for this

7
00:00:30,870 --> 00:00:31,590
first program.

8
00:00:31,620 --> 00:00:33,710
We're going to speed through the implementation very quickly.

9
00:00:33,960 --> 00:00:37,290
It's not going to have a lot of typescript specific syntax in it just yet.

10
00:00:37,710 --> 00:00:42,740
Remember, the goal of this first application is not to learn a bunch of different types of syntax.

11
00:00:42,750 --> 00:00:45,630
Instead, I just want to show you why TypeScript is handy.

12
00:00:46,470 --> 00:00:51,360
So to get started, we're going to first import that axios module that we just installed at the top

13
00:00:51,360 --> 00:00:51,840
of the file.

14
00:00:51,840 --> 00:00:55,440
I will write out import axios from Axios like so.

15
00:00:56,990 --> 00:01:02,420
After that, I'm going to flip back over to my browser, go to that JSON placeholder and point right

16
00:01:02,420 --> 00:01:07,580
here and copy of The Wall that's going to give me just the first to do.

17
00:01:08,600 --> 00:01:15,530
So a copy that you URL and go back over to my editor, I'm going to create a variable called URL in

18
00:01:15,530 --> 00:01:17,900
a sign that URL to it like so.

19
00:01:21,180 --> 00:01:27,440
So now we've got the URL in here, we can use Axios to make a network request to this URL to do so,

20
00:01:27,450 --> 00:01:31,500
I'll write out Axios Douget and then I'll pass in that URL.

21
00:01:32,450 --> 00:01:37,790
So it's going to make a http get request to that URL and attempt to fetch that JSON data.

22
00:01:38,640 --> 00:01:44,430
That entire operation is async, so by calling Axios Moorgate, we're going to receive a promise in

23
00:01:44,430 --> 00:01:44,940
return.

24
00:01:45,440 --> 00:01:50,970
So to get a notification on when the request is complete, we can change on a then statement that will

25
00:01:50,970 --> 00:01:51,540
be called.

26
00:01:52,930 --> 00:01:55,690
With the response once we get a response from that API.

27
00:01:58,350 --> 00:02:02,760
So then inside of here, remember, the goal here was to just console, log out the JSON data we get

28
00:02:02,760 --> 00:02:03,140
back.

29
00:02:03,360 --> 00:02:09,000
So I'm going to console log response data, which should be the actual to do that we received back from

30
00:02:09,000 --> 00:02:09,720
that API.

31
00:02:11,030 --> 00:02:14,440
All right, so let's save this, that's the entire program right here.

32
00:02:14,450 --> 00:02:18,110
We are going to make a couple of changes to it in just a moment, but let's try to figure out how to

33
00:02:18,110 --> 00:02:18,860
run this code.

34
00:02:18,860 --> 00:02:24,800
Now, remember, we cannot run tight script code directly inside the browser or with no Ge'ez.

35
00:02:25,130 --> 00:02:30,860
We have to first compile this file into plain JavaScript and then we can execute the resulting JavaScript

36
00:02:30,860 --> 00:02:31,220
code.

37
00:02:32,000 --> 00:02:35,630
So to compile this file right here, we will flip back over to our terminal.

38
00:02:37,890 --> 00:02:42,750
Inside of my terminal, I'm going to use the typescript compiler that we just installed two videos ago,

39
00:02:43,350 --> 00:02:49,530
we can access that compiler by writing out TSC remember, that stands for typescript compiler and then

40
00:02:49,530 --> 00:02:51,750
I'll feed in the name of the file that I want to compile.

41
00:02:53,200 --> 00:02:57,320
I'll run that command and I'll get kicked back over to my terminal almost instantly.

42
00:02:57,640 --> 00:03:01,090
So it seems like nothing happened, but the compilation did occur.

43
00:03:01,660 --> 00:03:06,940
If you flip back over your code editor and look at the file explorer on the left hand side, you'll

44
00:03:06,940 --> 00:03:10,000
see that we've got a new file inside of here called Indexed JS.

45
00:03:10,630 --> 00:03:13,300
So that is the compiled version of our typescript code.

46
00:03:14,080 --> 00:03:18,370
You can open up that file and you'll see what TypeScript did to our code base.

47
00:03:20,320 --> 00:03:26,120
All right, so now to run this, we can use the node command line tool and we'll run node index logs

48
00:03:26,140 --> 00:03:29,380
and that will execute the compile JavaScript file that we just created.

49
00:03:30,160 --> 00:03:33,280
So back at my terminal, I'll run node index dot James.

50
00:03:33,390 --> 00:03:34,540
Notice the extension on here.

51
00:03:34,540 --> 00:03:36,460
We are running the JavaScript file.

52
00:03:37,330 --> 00:03:41,470
So if I run that command, I'll then see the to do printed out on the screen.

53
00:03:42,280 --> 00:03:42,760
Perfect.

54
00:03:44,110 --> 00:03:50,020
All right, so as you might guess, having to always run TSC Index and then compile or something and

55
00:03:50,020 --> 00:03:53,430
then run that resulting file gets really old really quickly.

56
00:03:53,890 --> 00:03:56,470
So to combine these two commands into just one.

57
00:03:56,590 --> 00:04:01,360
We also installed a little module two videos ago called TEUs dash node.

58
00:04:02,620 --> 00:04:05,830
Dash node is going to combine these two commands into one.

59
00:04:06,640 --> 00:04:11,960
So it's going to automatically compile a given file and then automatically execute the resulting JavaScript.

60
00:04:12,400 --> 00:04:15,880
So it's just saving us from having to run that one extra command.

61
00:04:16,829 --> 00:04:23,930
So we can run, download, and then the name of the typescript file that we want to execute, so inducts.

62
00:04:25,570 --> 00:04:26,920
So then run that command.

63
00:04:28,490 --> 00:04:32,900
And then I should see my JSON printed out up there we go, a little bit of a pause there, I guess my

64
00:04:32,900 --> 00:04:36,410
Internet connection is a little bit spotty right now, but I saw the printout right there.

65
00:04:36,530 --> 00:04:40,100
So in one step, we compiled and then executed the resulting JavaScript.

66
00:04:41,010 --> 00:04:45,950
OK, so that's how we put together a very basic type of program and then execute it at the terminal,

67
00:04:46,590 --> 00:04:48,810
but I still haven't really shown you anything around.

68
00:04:48,960 --> 00:04:50,930
You know why TypeScript is handy here.

69
00:04:50,970 --> 00:04:52,380
So let's take a quick pause.

70
00:04:52,380 --> 00:04:55,860
And when we come back in the next video, we're going to start making a couple of changes to this program

71
00:04:56,040 --> 00:05:00,200
and we'll very quickly see why making use of typescript is really, really handy.

72
00:05:00,630 --> 00:05:02,600
It's a quick pause, and I'll see you in just a minute.

