All right, guys.
So we're getting ready to deploy to render.
There's just a couple things that we need to do to get that set up.
So first of all, we're going to go into our server.js and we're not going to have our React dev server
in production like we do locally where we run it on Port 3000.
We want the root of our application, our server to load the, the, the built version of React, the
production version.
So we're in the server.js.
Let's go down, we're going to go under.
Let's see, let's go right under the uploads right here and we're going to just do a test to see if
we're in production.
So we'll say if process dot env dot node underscore env if that is equal to production.
Then what we're going to do is set.
The react build folder to actually.
Yeah, we can just do this.
So we're going to set the React build folder, which is in our front end slash build.
Okay.
Because if you're, if you're building a React app and you do NPM run build, it creates a build folder
with all your static assets.
So we're setting that to be a static folder.
And then we're saying any route that is not, you know, not these routes for our API is going to be
redirected to index.html.
So app dot get star and then we're just using send file.
So basically we're just saying load the index.html that's in the front end build folder which we just
made static.
Okay.
Else so if we're not in production then we'll go ahead and just do this, which is just saying API is
running because if we're not in production then we're using the React dev server.
All right.
So we just want to do that.
And then we also want to create an NPM script to build from the root.
Because when we deploy to render, we're going to have we're going to enter a command to build, but
we don't want to, you know, run it from the just the server because it's going to it has to be run
in the front end folder.
So in our root package.json, let's create a script called build.
And this will also run NPM install on both sides.
So we're going to set this to NPM install.
And npm install dash dash prefix front end.
So that will run npm install in both the back end and front end.
And we're going to run npm run build dash dash prefix.
In the front end.
Okay, so.
So that way we can run npm run, build from the root and it will do all of this for us because it's
going to do that on the server on render when we deploy.
So let's save that.
And now if we run NPM, run, build from the root.
It should build into the front end folder.
So now if we look in front end, we'll actually let's let it finish, but it should create a build folder
in the front end.
Creating an optimized production build.
And you don't actually have to do this before you you push to to render because this happens on render
once you push.
Okay.
So now if we look in front end, now there's a build folder.
So basically our server, what we just did in our server is point to that file to load that file if
we're in production.
Now let's go into our dot env and let's set this to production.
Just temporarily.
And then let's go ahead and do just NPM run server, which only runs localhost 5000, not the React
dev server.
Now if we go to our browser and we go to 5000, we see our application.
So this is the production build.
In fact, if we click on the little React dev tool here, you'll see this page is using the production
build of react.
So this is essentially what we should see once we deploy.
It's the same thing.
It's just not running on the React dev server.
All right.
So the other thing that I did is in Package.json I'm sorry, not in dot env, I'm just going to set
this back to development.
I added this pagination limit here and set it to eight and then in the controller, the product controller
get products.
I set the page size to that.
Just so you know, if people are going to use this, then they can just set that in the dot env and
they don't have to come into the actual code to do it.
So just to make it easy on people that want to use this this platform.
All right.
So I think now we're ready to go, we're ready to deploy, so we'll do that in the next video.