Support People In Ukraine
Ukraine was invaded by Russia in the early morning of 24.02.2022, explosions thundered in Ukrainian cities, many civilians died, tens of millions are affected. Our army protects all Europe from the occupiers and it needs help now to restrain one of the biggest armies in the world. Please, donate a small amount.
I Am
Volodymyr Hudyma
<FrontEndDeveloper />
You Are Here: Home/Serve Build Folder In React

Serve Build Folder In React

March 01, 2021

Table Of Contents

    In some special cases, you may need to run the React production application locally.

    For example, if in the development environment the app works fine, but the production environment contains some strange errors.

    Debugging in the production is generally bad and time-consuming idea, because in order to add some logs, you would have to commit and re-deploy your changes.

    Fortunately, you can serve production build locally in a few simple steps.

    Create React Application

    Let's create React Application first:

    npx create-react-app test-app

    And run it to verify that the installation process completed successfully:

    yarn start

    You should see that the app is running:

    React App Running

    Build React Application

    When you are ready to deploy to production, an application should be built.

    Run the following command:

    yarn build

    And watch the logs:

    Build React App Logs

    The built application is available under the build folder.

    Now we need to run an app pretending that our local environment is the production one.

    Serve Build Folder

    The way to serve the build folder can be noticed in the above logs.

    React gives us a hint on how to do this:

    React Serve Build Folder Hint

    All we need to do is install serve globally and run it on our build folder:

    yarn global add serve


    serve -s build

    After running these commands, you should see which port your application is listening on:

    Served Built Folder Port

    Now just open the URL (localhost:5000) in the browser and see what happens there.

    To add some logs, you would have to re-build an application and serve it once again.


    Today we learned how to serve the build folder in React.

    It can be extremely useful when you need to quickly debug the production version of your React application without having to redeploy it every time, which adds unnecessary logs that can potentially be seen by your end-users.

    Receive all new posts directly to your e-mail
    No spam, only quality content twice a week
    Let me know what you think about this article
    Click here to write response...