Express JS Tutorial for Beginners in Hindi 🔥 Build Your First Express JS Server from Scratch

Thapa Technical
63 followers
Dec 27, 2024
Hello what's up guys today in this video
we will see introduction to express j
yes guys finally the one you
were waiting for and that is at nut express kab aayega,
when will it come, finally today it has come and today we will see
complete introduction to express js and
How to create a server in express just like
that today we are going to watch a video on it so guys
you must watch the video till the end and
before that if you have not checked out our note series till now then
please check it out
we have made a mini five project
and I made a little URL short nut a little
mega project, so you must
check it out and also guys
if you haven't subscribed to my awesome channel that technical yet,
please do so
so that you don't miss such awesome videos daily,
alright Guys so first of all what is
express jess because we were already studying the node
we have read it we have done everything
but even after knowing node why we need to
learn express jess this is an important
question okay so it is very clear you
can see it here yes That a simple one
line is written, if you read it,
then all your doubts will be cleared, so
here you can see very clearly that
X phrases is a minimal and flexible
web application framework for not just
based on STTP module so basically This
is now a framework for you, just like express
is a framework with the help of which you
can now very easily create your servers. The
work that you used to do in end node, you can do it
here very easily by writing minimal code
and in a very flexible way. You
can create it, okay you should
understand that whatever work you used to do in JavaScript,
after that guys we have React
and it has become so easy it is just your
library then we have another J which
was your framework so So we have
this node and we have this framework called
express node simple so it is
working like this here it is okay and don't
worry when we see the code then you will know
and I will also show side by side
that When you're nuts You create a server on express and
then when you create a server on express which one
of the two is the fastest and it
gets created very easily then the second thing which is
important and that is express judge which is
yours it's simple the routing which
is routing like You
go to different pages and all these things happen right below the
middleware, you know we will read further, don't worry about
handling HTTP requests in a
Node application, guys, it simplifies all this further, there are
two VRs in our Node application. Working with express but
still we will not call it a node application
and these three things that you can see,
however apart from this there are many other things
that is routing middle ware and how to
handle your HTTP request, it makes it very
simple and very childish. Do you
understand now it is extremely popular, here
you can see very clearly that it is
extremely popular with wide community
support and there are also alternatives
Obviously there will be many alternatives, out of
which you must have
heard a lot about Fastify, we have a
next, this is not your react NE X
one, yes this is your s,
you are seeing here, it is s, probably this If
next is installed then this is not next
it's
nest dot jae den ko h LS JS in this way now now I
hope you got to know about
express JS you should understand that this
is your framework now with the help of which
you can make any note application We used to create it,
now it has been simplified further, like
in routing, ATTP requests have to be handled in the middle ware
and we have
understood many things, that's all, when we see the code one
by one, you will know everything
and here is one thing you will notice You have to keep in mind
and that is when you simply install
your express using the npn
command then it installs the version four which it
installs the version four but
recently like after many years I will say
that Version five is finally stable now
and now we are going to work with version five which is the latest one.
We have also worked with React version 19 which is the
latest one. If you remember like we have this
React version 19 2025 ready so
Check this out as well, in the same way, there is a
version five of express, okay, so now
I will tell you how to install it
and now we will see how to create a server,
so this is the folder
structure that we will see now Till now you have been looking at
our node application and now I will
share this with all of you, okay so
you do one thing, create a new folder here,
whose name will be
express, okay, what will its name be, we have
an express, okay Hey once guy, we
come to the express folder, then
make sure we need to have the package.json file.
Okay, if you
go to install express directly, then it will happen in its
root folder, wherever the package is. The
express will go there and
install the .json file in this way but I don't
want that. I want
my package dj file to be inside the express folder only and
I should do all my work there only because
I can't install all the other files which are outside. I will
add it inside the note folder now, you understand
what I am saying, right? So you have to do
this, we need to create one a package, I
mean package Jan Fall, then NPA it and
even if you had written hi you, your work would have been done. So
let me name it your express. Just keep
hitting enter enter enter enter
and finish. Okay, so this is what you can
see. The thing that you can see here,
that happens to you, there
is no tension. no simply you
come here and clear it npm install and
then we need to go with express okay
we have seen this thousand times simplified now you
can see one thing here and that is
when you write npm install express for the first time
Then it installs your version four
but we
need version five which is It has become stable
right, so there is nothing to do, there is
no tension, there are many ways to install it
right, but what we will do is we will
directly go with the same code but @
5.0.0 simple right just hit this link if
you do If you give it to me then guys, you can see this very
easily, your work would have been done
and here now you can see that
your version five has been updated and
guys if you think that version 5.0
something has already arrived, right if you That also needs to be checked
out, we have already seen that it is
with the help of this NPA NPM
han check the update, if you hit enter then it will
tell you here that oh my God, okay,
so basically everything is completely up to date This is
our latest package, we are working, there is
no problem, it's okay, it's a good thing,
let's leave it as it is, now our file is
ready, now you can see it on express,
so now I have a node underscore models,
I already mentioned it above. have we have a The
package is lagged as I have told you above also,
so by default when you
install express then this has to be there
or when you install any package then this has to be there,
so go to express and
create a new file. Wait a second,
come here and create a new file and that
is app.js this is it that's all you need to do
come here now what we need to do we
need to import express okay or
xpress from obviously our express okay
This is how you have to import it
Now we need to create an instance of our
express application Okay so basically
we are creating an instance And one
second I will put it for you in this way
so that you know what the guys are
Look here, if you
create an instance in this way, then you can define a route for your express
application. Now with the help of this
instance you can define a route. Remember
we told you that this simplifies your route routing.
hey this is how it is like get a
post extra and yesterday
in how the web works i told you that there is
no middleware like it is used very
easily with the help of this use method you can
define your middleware then server if
listen If you want to do that then add license then these are all the
things, don't worry, I will share them but
we imported express from our
express library basically framework
and then guys we simply created instance
from our express application
now first of all we have to create a guys server
Server means that tomorrow if I
go to localhost, suppose it is on 3000 or 3001, then it
should show me my home page, hello world, it will be so much fun,
right, it is so easy here, we have this
pop as an Instance dot we have this routing
click get method now guys here we have a two
parameters which you have to keep in mind
always and that is the number one Is the path like
this give it forward slash like right now my
home page by default it's your home page
right index file else if you want to
go to the about route then you go to the about page
like this if you want to
go to the contact page then you go to This is how the contact route is
created. Don't worry, we will
create everything. For now, this is your home page. And
then second is your guys' call back function.
Second is your call back function. And this is also
very important. Okay, here
we have a Request and then we have a
response and whenever someone hits this route
then we will send a response
and that is hello world right hello so now
you guys have created a route
call it route or call it route you have created this That's
done, now what do we have to do with the server,
guys, we have to listen. This means
that if someone goes and hits this route on the local host,
then we have to remain active like, if
someone makes a request,
then we have to listen. will have to Right so it's
you do listen and then again here also we have to
pass the port number first we need to
pass the port number okay and then comma
one second not a prompt it's a port comma
and then your call back function okay call Back
function means if they go to this port then do
you want to show them anything after that?
Yes, I want to show them. I want to show them in the console dialog.
Whatever the number is, in this way. And
here put the dollar, I will keep your port
here. I would like to give you Alright now the
thing is I haven't created this port yet
so I will go to the top here or it's
okay for now I will
keep it here I mean I won't complicate it I will
keep it here and say hmm
you can run it on 3000 ok this is
it is so easy to create your server in express
just import the
express and then we need to create an
instance of our express application and
then we need to put all the things inside it is
obtained That is app.get I
want to access the home page so whenever someone
accesses the home page then we will
show him the word hello in raced s and then
I am simply listening here so
in the kind of guys node also we have I did it like this,
control s, save it and quickly do one thing,
come to the package d json file here,
come below it, here we need to type one more
thing and that is typed, right, and
here you module it, else. Then you will
not be able to use that yes module and by the
way if there are double quotes everywhere then
you should put double quotes here also in this manner, it is
necessary to write this, so that you can use the functionalities of
import and export in this manner
can you do it so now it's just
your node nfan app.js alright guys c we
have a server running at 3000 now if I
go here so it's your 3000 right
and hit enter boom guy c We have
this Hello world now I will tell you some
small differences which you will
like and that is if I
go on the network okay if I
hit request then the first
thing you have to see is that they have bought By
default, a status code has been assigned here. So the
thing to see is that it
should have been 200, but we are getting a
304 Not Modified because this
was your text file.
Remember our previous code.
What do we have to do every time? If I
show you, we have a URL sort of
project. Okay, as far as I remember, we have the
complete status code. Yes, look,
on the right hand side, I have shown its
status code like this and then the content type is application
for sjan or this or that. Content type text
f ata I was doing so much right this
is also the same and at the end I see the server dot
lin port this is kind of the same
right and here request dot method
equal to equal to post and here you
can see it on Request dot method
equal to get and then request dual
equal see this was two lines in express
it got done in just one line ad dot get
this is it and this is it are you understanding here the
two lines were get method and Then this is
your forward sl route here it is
done in one go, your work is done in one line, is
n't it, it is so awesome, this right
and now I will tell you the beauty by I mean,
look carefully here, all this This is
happening isn't it brother a text d htl1041
now the beauty is that express is
so capable in itself that it will understand
what response we are sending right now
if I go here okay
look carefully here Right now the status
code here is this and if you look at this place then
we don't have any content type yet
you don't see the content type here but the
moment I refresh and boom guy see
we have this local host first of all so you
see it's your 200 type is your
document if I go on this
again here we can see our status code it's
200 method is your get a port number is
3000 and the beauty is that by default
whatever your content type is now it's your
text fav s html5 this is the
length of the character and this connection is telling keep alive which
means it will keep running and powered by you
can see here we have this
express so the first beauty is that it
completely simplifies your routing
see how simplified it is It's done now we don't
need to specify like that status
code our content type because by default
it understands what we are sharing
but yes it is what we call like one and
not a good coder would type that
Why don't we leave the express page
but this one is small right so guys in the same way
if I go here let's say
if someone wants to request the about page
wants to visit the about page So
hello about page you just do this empty okay
now if I go here forward sl have
about page and boom guys see hello about
page and here also you can see it's your
about if I click then everything is
same this which You will get it,
what you got a while back, look at
html5 and then get method, so guys, in this way you
can do your work and if you had to
write this in two lines,
okay, then from lets, if you go
to contact And lets say you had to
write it in two lines, then you would
have to give a bud brace here, okay and this code,
I will place it on top in this manner
and by the way, remove this part here as well,
you can do this In this way, okay, so by
default it is prettier, so it gets set automatically in
this way and here you
can do a lot, let me do one thing
quickly, do I have the code of ATML, do I
have HTML code, yes for public it
should be inside ok perfect let me do one thing
contact Contact Oh my God or
awesome this particular code
I am going to copy it and paste it here
okay now this is the code already I
am deleting it and I am going to paste it like this
so now you can see Maybe
you can see something like this but if I
put a back tick here then I will
not have any problem, okay, switch the control as well,
let's check it out, what happens, right
and yes one thing, whenever you do Kali in this way You are
using braces then make sure to
return the keyword so that whenever someone
wants to visit the contact page then we can show them this thing.
Okay and let's go here also once on
inspect so we have a contact so guys
What can be the test moment,
what will be the output, let's see 3 to v and boom
guys see oh my god just look at this guys
you are running your back end and
in your back end guys you have
created a contact form, understand yes this
is your back end if you If you did this then it would have been a different
thing but you can create a contact form on your express app
and
guys in this way you
can create your servers and I will tell you further that we
have different template engines
with the help of which you can create a contact form. You can very easily tackle
all these things, but how to do it on a single line
or on multiple lines, you can share whatever code you like,
I showed you
right how you can create routes, routing,
call back functions and all those things, so
or Guys this is it for today, I
hope you liked the video very much
and just by seeing this
you must have realized
how simple it is to create a server in Express now,
right and believe me guys, now move ahead There
is a lot to be got, a lot, I
don't want you to miss it, so guys, so
guys, please do like this video,
share it with friends and
also check out the rest of the playlists like previous notes. Because
in this also I did back to back five hits at the end
If you create a project then you will enjoy it.
So guys, how did you like today's video? Let
me know in the comment section. If you have any doubts,
then definitely tell me. I will definitely help you.
And once again, if you have not yet subscribed, then
please do and the next target is 8. I
get one lakh subscribers right so guys
I will show you in tomorrow's video till then guys
thank you so much take care
[music]
