DEV Community

Tao Liu
Tao Liu

Posted on • Updated on

If S3 buckets are for static file hosting, and not for running server side code, then why do we host react sites on S3?

Node.js and Webpack are often used for server-side tasks like bundling and optimizing code. However, in the context of hosting a React app on an S3 bucket, Node.js and Webpack are used during the development and build process, not at runtime on the server.

When you build a React app, you use Node.js and Webpack to bundle your code into a single JavaScript file that can be served to the client. The resulting bundled file contains the client-side JavaScript code that runs in the user's browser, not on the server.

Once the React app is built and bundled, you can deploy the static files to an S3 bucket, which is a simple storage service that can serve files over the internet. When a user visits your React app hosted on S3, their browser downloads the static files from the S3 bucket and runs the JavaScript code on the client-side, not on the server.

In contrast, a Rails or Flask application typically requires server-side code to run, as these applications often generate HTML pages dynamically and handle user requests on the server. This requires a server environment that can run the application code, process incoming requests, and generate responses dynamically.

While Node.js and Webpack are used during the build process of a React app, they are not used to run the application on the server. Hosting a server-side application, such as a Rails or Flask app, requires a different hosting solution than hosting a static website on S3.

Top comments (0)