Now we've got our project all set up and ready to go we can start to actually write out some code so
to get started.
I'm gonna create a new file inside my project directory called index dot T.S..
Notice the file extension on here is dot t yes a start for as you might guess typescript we're always
going to place all of our typescript code into dot t us files.
So now inside this file we can start to actually write out some code to implement our program and just
as a quick reminder Our goal here is to fetch some Jason data and print the results for this first program.
We're going to speed through the implementation very quickly.
It's not going to have a lot of typescript specific syntax in it just yet.
Remember the goal of this first application is not to learn a bunch of different typescript syntax.
Instead I just want to show you why typescript is handy so to get started.
We're going to first import that axiom module that we just installed at the top of the file.
I will write out import axioms from axioms like so after that I'm going to put back over to my browser
go to that Jason Place holder end point right here and copy of you are the URL that's going to give
me just the first to do so.
Copy that your URL and go back over to my editor.
I'm going to create a variable called You Are L in a sign that you are L to it like so
now we've got the URL in here we can use axioms to make a network request to this you are L to do so
I'll write out axioms dot get and then I'll pass in that you are L that's gonna make a h TTP get request
to that your l an attempt to fetch that Jason data that entire operation is async.
So by calling axiom dot gets we're going to receive a promise in return.
So to get a notification on when the request is complete we can chain on a dot then statement that will
be called with the response.
Once we get a response from that API
so then inside of here.
Remember the goal here was to just console log out the Jason data we get back so going to console log
response dot data which should be the actual to do that we receive back from that API.
All right so let's save this.
That's the entire program right here.
We are gonna make a couple of changes to it in just a moment but lets us try to figure out how to run
this code now.
Remember we can not run typescript code directly inside the browser or with no J Yes we have to first
compile this file into plain javascript and then we can execute the resulting javascript code so to
compile this file right here we will flip back over to our terminal inside of my terminal I'm going
to use the typescript compiler that we just installed two videos ago.
We can access that compiler by writing out TSC.
Remember that stands for a typescript compiler and then I'll feed in the name of the file that I want
to compile or run that command and I'll get kicked back over to my terminal almost instantly.
So it seems like nothing happened but the compilation did occur.
If you flip back over to your code editor and look at the file explorer on the left hand side you'll
see that we've got a new file inside of here called index dot J.S. so that is the compiled version of
our typescript code.
You can open up that file and you'll see what typescript did to our code base all right.
So now to run this we can use the node command line tool and we'll run node index dot J us and that
will execute the compile JavaScript file that we just created.
So back at my terminal I'll run node index dot J.S..
Notice the extension on here.
We are running the javascript file so if I run that command I'll then see the to do printed out on the
screen.
Perfect all right.
So as you might guess having to always run TSC index dot to us and then compile or something and then
run that resulting file gets really old really quickly.
So to combine these two commands into just one.
We also installed a little module two videos ago called T S dash node just a dash node is going to combine
these two commands into one so it's going to automatically compile a given file and then automatically
execute the resulting javascript.
So it's just saving us from having to run that one extra command so we can run T S dash node and then
the name of the typescript file that we want to execute.
So index Dot T S so then run that command.
And then I should see my Jason printed out.
Yep there we go.
A little bit of a pause there I guess my internet connection is a little bit spotty right now but I
saw the printout right there.
So in one step we compiled and then executed the resulting javascript OK.
So that's how we put together a very basic types good program and then execute it at the terminal.
But I still haven't really shown you anything around you know why typescript is handy here.
So let's take a quick pause and when we come back the next video we're gonna start making a couple of
changes to this program and we'll very quickly see why making use of typescript is really really handy.
So quick pause and I'll see you in just a minute.