All right.
So now that you've got Node and Hyper installed, it's time to check it out and see what we can do
using Node.js.
So the first thing I'm going to do is I'm going to create a new folder on my desktop.
But this time I'm going to do it slightly differently.
I'm going to be using our brand new Hyper Terminal, and we can issue it commands in order to get it to
do what we want.
So the first thing I'm going to type is pwd,
and this stands for print working directory,
so print where we are currently. Now working with the command line involves a little bit of imagination.
You have to be able to imagine where you are in this giant filing cabinet.
So, for example, you might have a cabinet and it has three drawers. Inside the first drawer
there might be three folders. Inside the first folder
there might be another three folders.
So this is how directories work on your computer.
And we're going to go into this in a lot more detail in the next module, where we explore everything
that we can do using the command line.
But here's a little bit of a taster, or a sneak peek, of the fun things that are yet to come.
So by using the pwd command and hitting enter,
we get printed out a number of lines that shows us where we are in this giant filing cabinet.
So the starting point is called the root,
and then we're inside a folder called Users,
and inside that folder there's another folder called angelayu.
So if you're used to a graphical interface, this is basically where we are. We’re inside this current folder,
and you can see that the folder above it is called Users,
and then if I double click on this folder called angelayu, then I get into my home folder, and from here
you can see that we have our Desktop folder.
So in order to move over there, then all I have to do is write cd, which is the command, and it stands for
change directory, or change folders, and we're going to change over to Desktop.
Now you can either type it out entirely, so Desktop. I don’t know why I just turned
Japanese just now. Or you can simply start writing, say De, and then you can hit the tab in order for
it to auto complete.
Now, for example, if you only wrote the word D and you have multiple items like Documents, Downloads, Desktop,
then it won't know what to suggest, so it won't come up with anything.
But if you give it enough characters for it to be able to identify a unique name, then hitting that tab key
will auto fill the rest of it.
So now, if I hit enter, I am now inside the Desktop folder. As you can see, that's what's showing up. At
the colon is our current location. And we can confirm that with the full directory path by using pwd. You can see
that we're inside Desktop, which is inside angelayu, which is inside Users.
Now once we're on to the Desktop, so I'm going to do it side by side with Finder over here as well,
now once we're inside Desktop, we can use a command called ls which simply just lists everything that
currently exists inside our location.
So now we can see what exists here.
And we've got something called Web Development, something called App Development, two folders.
Now, if I wanted to make a new folder at this current location, Desktop, all I have to do is write the
command make dir, or mkdir, and this makes a new directory, or rather new folder.
It's the equivalent of hitting right click and clicking on New Folder.
And then we have to specify the name of the folder, and I'm going to call mine intro-to-node.
So you can have it capitalized if you want, but I'm just going to keep it lower caps
and also with hyphens in between.
And now, if I hit enter, I have a new folder called intro-to-node.
Cool, right? Now, if you haven’t used command line before,
it really is built for power users, because we can do so much stuff that Apple or Windows has kept
away from us.
And I think using the graphical interface is kind of like riding a bicycle with training wheels.
This is more like a full blown Hayabusa motorcycle. With great power comes great responsibility, and
we're going to talk a lot more about that in the command line module that's yet to come.
But now that we've created our folder called intro-to-node, I'm going to then cd, or change directory, into
that folder.
And now I am inside this location,
so the equivalent of being here.
And if I hit ls here you can see that there's nothing.
It's completely empty so far.
So we're going to create a new file here, and the command for creating new files is touch.
So we're going to say touch and then we're going to specify the name of the file.
So we're going to say touch index.js.
And now, if I hit enter, you can see, wow, brand new file that's just been created out of mid air.
So if we double click on this, it should open up in Atom. If it doesn't,
then make sure you right click and tell it where to open to, which is Atom.
And inside this file, we’re going to simply create a console.log that just says, “Hello, world!”
Up till now, we've only been able to run this code if we incorporated it into an HTML file and opened
it inside our browser.
But now we're going to do something slightly crazy.
We're going to run this code using our computer, and we can do that by simply being inside the folder
where that file exists,
so when I hit ls I should be able to see the file that I want to run, and then I'm going to use the
command node index.js.
So this says use Node to run this file.
And now, if I hit enter, you can see that the result of that file, which was simply to console.log “Hello,
world!”, gets executed, and it gets logged inside my Hyper Terminal.
So that was our first Node.js file that we executed.
Now, in the next lesson, I want to talk to you about the REPL, the Read Evaluation Print Loop.
So for all of that and more, I’ll see you on the next lesson.