Welcome back.
In this video, let's write our first Node.js application.
So I'm going to show you how we can start to create Node.js application and how we can run it.
So let's get started.
Well, so we are going to use the terminal and then Visual Studio code so you can use any text editor
of your choice.
So the first thing you need to bear in mind is what we need to create a folder where we are going to
keep all our Node.js applications in the same way when we are developing front end application using
HTML, JavaScript and CSS.
So the same steps here.
So now I'm going to use the terminal.
I'm going to show you two ways you can use the terminal to do everything or we can blend using the mouse
and a terminal.
So here we go.
The first thing is we need to create a folder.
So if we want to use the terminal, advise you to stick to the terminal to be familiar with the commands.
So here we go.
First thing is we need to know where we want to create the folder.
So first of all, I want to know where I am on my terminal here.
I'm inside my command folder, so I don't want that.
I want to go back and I want to check the folders in here.
It means that I am on my desktop.
So my desktop I can create a folder on my desktop and I can do it manually by right clicking and create
it.
So first of all, let's do it manually.
So right click and let's say that node sorry, rename it here as node JS Guide.
You can name it whatever you want.
So this is my Node.js guide.
I have done it manually.
Perfect.
Or I can use the terminal to do it.
So let me clear the console now.
Let me remove this one.
Now let me create to make use of m k d r is going to be node js, space guide hit enter and now it has
created it's here for me on my desktop here.
Now after creating I need to open this folder using my text editor and for me I'm going to use Visual
Studio code so I will drag it and place it inside my Visual Studio code.
And better still, we can use the command to open inside Visual Studio code.
If you are using Visual Studio code, first of all, c d into the folder called Node.js.
Now let me clear the console.
Now to open it, I'm going to make use of code and then period hit enter and now I can see that it has
opened for me.
So if we want to do it manually, we can drag and drop or we can use code dot and then you are good
to go in case you couldn't do it or you couldn't open.
Don't worry, leave a question below.
Now we have opened our project inside our Visual Studio code with the folder name called Node JS.
The next step is we need to create a file.
If you are developing, let's say, JavaScript or CSA, definitely I'm going to create a file with an
extension or dot HTML or CSS.
But because we are going to write Node.js, energy is JavaScript, we are going to use the same extension
as JavaScript.
Oh, right.
So again, we can do it manually by clicking and create a file and better stuff.
We can use the terminal to achieve that.
So here we go.
So the terminal going to make use of touch and the name of the file make it app dot js.
So hit the name can be anything.
It can be my app, it can be server, it can be index.
But for Node.js applications, we normally use app or server or index, so these three file names are
commonly used.
So because Node.js about server, let me make it at server third JS hit enter.
Now let's check my visualized code.
Now I have the file here called server JS because Node.js is JavaScript, right?
So now I have the file.
The next step is how can I write Node.js code?
And here we go.
Remember that guys, Node.js is JavaScript, so it means that we are going to write JavaScript code.
But upon running the V8 engine is going to run the code on the server.
So we're going to take all the complexity from us.
So all what we need to do is to write JavaScript code.
So here we can write any valid note, any valid JavaScript code here.
So let's write our first Node.js application.
So here we go, console the slug and let's say here as my first node.
JS app.
Now I have finished creating my first application.
So guys, how can I run this application?
How can I see the result?
All right.
Let me show you here, guys.
This step is really important, so pay attention carefully.
So let me clear my console or my terminal as that.
So how can I run it?
First step is we type in Node.
Make sure that guys you are inside the folder where your file is.
Remember I'm inside the node JS folder as that.
Perfect.
So here you make use of node and then space the name of the file which is server dot js which is this
file meaning I'm using node to run the file and that is it and that is it.
Guy so let me hit enter and now we see that my first Node.js application, how easy it is.
All right.
So lucky for us, Visual Studio Code is also versatile, meaning that by default, Visual Studio Code
has a built in terminal that we can use.
So here we go.
So as we move on or be switching from not using this terminal, but instead I'm going to use the built
in terminal that came with Visual Studio code.
So let's see how we can open it.
So move your mouse and the explorer.
You can see here we have terminal and then click on terminal and we have it here.
All right.
So let me collapse this sidebar.
You can say that the same way we use the in terminal, we have it down here.
We see where we are on our folder, our project and inside the Node.js guide folder, which is the same
as this.
And by default we are using as a share.
As you talk about don't worry about this or what we need is how we can execute command here so we can
also achieve the same way.
When you open the Explorer here, we can right click and say open an integrated terminal, which the
same as the path.
For me it just open it twice, the first one and the second one.
So let me close one right click and click on Kill Terminal.
Now here we go.
So now I am inside my Node.js folder.
So the command I can issue here, I can do the same thing here also.
So if I want to know the files and folders inside this folder, make use of LS.
And now we see that I have one file which is indeed this one.
So how can I run it the same way?
Node space the file name Dot JZ and now I see my first Node.js application.
So we can write any valid JavaScript syntax.
So again, let's create a function that are two numbers, very simple one, so you can see.
Let's see some.
Is equal to, let's say, for this one A and B and use a function here and just consider that log A
plus B, so if I call it the function sum and then pass in to and for now if I run my application now
I have six.
Yeah.
Is it.
And the same way I can run the same code here and I have six.
That is it.
That is it guy.
So now that we know how to write JavaScript code in this video, let's get started with the actual emojis.
Syntax.
No.
Syntax No.
Yes.
Concept by talking about what is called the Node.js module system.
So guys, catch you up the next video.