So it's time for a five minute crash course of node and JavaScript.
Obviously, that's not enough time to even scratch the surface, but I'm just going to show you the
basics of what you need to know for us to continue on with the course.
OC So back over in Cloud nine, we will delete everything.
Get rid of it so you can do that either.
If you want to use a command line, you could do use arm and dash RF or just.
Highlight what you need to delete right click and where is that delete?
And then we'll say yes to all.
We want to remove all of it and we're home free now.
Can get rid of some of this stuff.
Perfect.
Make some space.
I'll bring this up a bit.
And now all that we're going to do is make our first JavaScript file.
We can call it whatever we want.
You can either use touch apks or you don't have to call it JS or you can right click over here and click
on New File.
I'll do that one and I will call this well I'll do JS.
It's a standard name.
And I won't recreate it down here.
Now we'll open it up, double click, and we'll add some JavaScript in here.
So what I want to show you is this basic workflow with Node that we kind of saw already.
We typed some code in the file, we save it, and then we execute the file with the command node space
and then the name of the file.
So it's very similar, at least in principle, to what we did with the SQL Files, where we would save
a SQL file ending in SQL.
Put something in there, a query, then we would execute it using source and then some file name dot
SQL.
Same idea.
So I'm going to show you some very simple code.
There's something called.
And again, if you know this stuff, feel free to skip it.
Something called console.log.
Kind of the simplest possible command you can do in my SQL.
It will just print something out so we can do our basic.
Hello.
Oops, we don't need caps.
Hello world.
And we'll put a semicolon there, which should seem familiar from my SQL at least.
And let's start with this.
Our first application, very basic.
If all we need to do to execute it is come down here and type node and the name of the file which we
called app dot js.
And it runs silly, but it works.
Okay, so that doesn't seem useful, of course, but it's something, right?
And to see kind of why a programming language would be useful, let's at least do this 500 times.
Let's.
Maybe that's not useful, but we can at least see how it's helpful.
It's doing something that we can't do on our own so we can create a simple loop.
We'll do less than 500.
Now, in my other courses, this is like an entire video, five or 10 minutes with exercises, but I'm
not going to spend time on that.
What this here does is it says whatever's inside of here repeat 500 times.
Basically, this is a counter saying, okay, we're starting at zero.
And every time through the loop we're going to add one to I, which is what this does here.
So we go zero next time around.
One, two, three, keep going.
While it's less than 500.
As soon as it hits 500, we're done.
Okay, so if I just put that in there, whatever is in these brackets here will happen 500 times.
Let's do it.
Now, one thing that I could add that I probably should is this var keyword.
It's just don't worry about it, but it's important to have it there.
Now, if I run it and I scroll up, I can see we get hundreds of hello world's well 500 so imagine you
might be wondering why do you care.
Well, imagine instead of console.log what if we had insert a new user into the database?
That would be a fantastic way to quickly see the database with a bunch of data.
Remember how we had to do this obnoxious copy and paste?
So I would give you a file.
You would copy and paste.
Like for the movies, data and review service, these big files you had to copy and paste it in.
It's an awful way of of getting sample data.
Well, we can use JavaScript to create data for us.
So just a couple other things that I'll show you.
We can do math and basic things like five plus five and I won't do this 500 times.
We can comment things out, selecting them and doing command slash so that won't run anymore.
So now I'm only running five plus five.
You can see we get ten.
One other thing to address is what?
What is Node if you're not familiar with it and it's actually a pretty common question.
There's a bit of confusion about Node Node.js, which is what it's called, and regular JavaScript and
what the difference is.
Basically, JavaScript is a programming language.
It was created first.
It's been around for a while and it's existed as a language that you can use on the client side.
So what that means is that back on this diagram, there's a line right here, not right now, but imagine
a line.
This is the client side.
So I could write JavaScript code that did things over on someone like on my computer.
You could write code that would animate something or make a game or just add some pretty effects.
That's not to say that it's not powerful, but traditionally it was used kind of to decorate pages,
if you will, and it had nothing to do with databases.
It had nothing to do with servers.
You would use another language over here like PHP and you would use JavaScript on the client side of
the front end.
But then Node came around about five years ago now and what it is, is an implementation of JavaScript
written so that you can use it on the back end, so that you can do things like this.
You can create a server with JavaScript instead of having to do it with Ruby or PHP, and it can talk
to a database like any other server side language.
So to summarize that node is JavaScript.
It uses basically the exact same syntax, but you can use it on the back end, which is what we'll be
doing in this course.