Hey, did everyone take share?
And in this video, we'll be flipping back and forth between index chairs and dogs.
We'll try to set up a basic structure so that we see something on the screen, at least as a result.
Okay.
So how we're going to be working with that first package draw?
Jason, we need to create some of the scripts just like we have done in the past as well.
The first one is always going to be the start script, which is majorly going to be there on the servers
usually.
So this is going to be run by the node environment, whatever the environment you have mentioned up
here.
And then we just want to target one thing which is index or JS, but similar to this, we want to run
things into dev environment as well.
So what we're going to do is instead of the node, we're going to say, hey, please, let's just run
this with Node one and let's go ahead and say that this instead of the start, this is a dev script
for development.
But again, there can be a whole lot of configuration of providing the environment, whether this is
a production environment, development environment, and all of these things can go up here like people
just try to set the environment and all of that.
We'll be doing that through the dot and V file as well.
This reminds me that we need to create the dot and V file as well, so let's go ahead and create a dot
E and V file.
Now again, a big reminder, some people like to put this dot and V file into config.
Feel free to go ahead and do that.
I like to keep it into the root of the structure.
This is majorly being done by majority of the organization.
In case you are putting it up into config or any other place, you have to mention that path always
while configuring it.
So that's what basic is.
So if we go ahead and say, hey, we need to run it through on the port 4000, that is fine.
We'll be connecting with the port just from here all the time, not even once on the local development
any other way.
Okay.
So this is the basics we have gone through with that.
Now let's go ahead and move into JS.
So here the first thing that we need is express that is going to be coming from require express.
Let's go ahead and create an app from this one.
So we're going to go ahead and say, hey, I want to create an app from Express.
So there we go and there we go.
Not like that, of course.
There we go.
So, okay, so now our Express app is ready.
Now we won't be doing anything with this app.
We will be just exporting this.
So I'll be writing a lot of comments in this course for you.
So in this section, especially so export app.
JS So how do we export that?
We simply go ahead and say a module dot exports that is going to be equal to app.
So whatever is now happening inside that, we'll keep it just into app dogs.
But one thing who is responsible for starting or initializing our application is going to be indexed
or.
JS So the first thing that is let's bring in the app itself.
So that is going to be require since it's in the same directory, I can just go ahead and say dot slash
of course in the codes dot dot slash app.
Now this app is here.
I can use this app just like I would have been using it into app file.
So let's go ahead and kind of create a basic server for that.
So we can just go directly go ahead and say app listen or you can hold that server into a variable,
maybe you want to use it later on or something like that.
Let's go ahead and say that I just want to directly use that app.
Listen, so how you want to listen on which port?
So for that we'll be having process dot E and V E and V dot port, of course.
Now onto this one.
Further down the road, I would like to fire up a callback function just like this.
And this is simply going to log a message for me, of course in the back takes that will say server
is running, running, come on at port and then we are going to inject available just like this and
we'll be saying same process, dot E and V dot port.
Now the important thing is this is not going to work.
Let's go ahead and save this one and I go ahead and say npm, run Dev, this should fail right now.
So there we go.
It says server is running at port, but port is undefined.
The reason for that is it doesn't know from where to where to bring in the port.
You just said, hey, process that tab.
But I don't know what this process E and V is for you.
So I need to make sure that I go ahead and require this one up here.
So just up here, I'm going to go ahead and say, Hey, I don't need to hold a reference of it.
I can just go ahead and directly say that, Hey, I'm going to need this dot E and V, so I'm going
to go ahead and say, Hey, I, come on.
Here.
I'll just say, hey, I require a package.
The package name is Dot, E and V and I can go ahead and simply on.
I can chain a config on that.
I don't need to pass on anything there in case you have got something different.
Like for example, you have got your E and V file into config or somewhere else, then you need to provide
that path and sometimes you also need to import the path from there.
Now as soon as you do this, you are going to see that server is running at Port 4000 because Node one
is refreshing it all the time.
So this is all great and fine so far.
Now also, sometimes you are going to notice that all this is if you load it up here, it is going to
just go through everywhere into JSON, everything.
But I have noticed that sometimes it creates an issue and it is kind of sometimes just you avoid the
issue if you load it up here.
Although although let me remind you again that if you load it up in the index, that is the main file,
that means it has loaded up into all of your application.
But I have been into a strange, weird situation where just adding this line actually fixes that up.
And again, if you have more information on that, please do share me.
I have tried to debug it line by line and sometimes it requires it up here as well as there as well.
Again, very strange situation.
I'm still trying to learn that part up here.
Okay, so this is all basics of it.
Now we have gone through with our server is up and running.
Now in the next video we are going to go ahead and create the basic first home page route.
It's going to be a dummy route, but will help us to understand the architecture of the application.
Let's go there and catch up in the next one.