Can I deploy react.js web app to a share hosting?

Use npm run build, you should get a folder with the index html file inside that will run your app. Try this with xampp first before you actually deploy to your server.

Here is everything step by step

npm run build

or

yarn run build

it will generate a build folder that looks like this:

enter image description here

Copy everything and move it to the htdocs in xampp or ftp upload the directory to the public_html file in your hosting


Yes you sure can put react on a shared hosting provider.

Seeing as you're getting a 404 error (not found), you are probably referencing your react file/bundle incorrectly. It might not even be named bundle.js if you're using a boilerplate to create your application.

Can you give more information? What does your index.html file look like? What does your directory structure look like? If you are able to post these files I can tell you what the issue is.

Update: The answer below should be accepted. (Although this would assume that you have the ability to make a build which you have not verified or not.)

Make a build using the build command through whatever boilerplate you used. Deploy those files on your shared hosting server. Make sure that index.html is at the root of where your server is expecting the root to be and your app should be live.


For deploying a react app on a shared hosting you need to create a production build. Production build is a pack of all your react code and its dependencies.

in most shared hosting we put our site/app inside a public_html directory so if we hit www.yourdomain.com it serves the code from public_html directory.

so if your react app is ready to go, edit your package.json file add a new key value:

"homepage":"http://yourdomain.com"

then create a build using following command:

npm run build

after running the command you will see a new directory named build in your app root. It will contain js and css for the app and a index.html file. You need to upload all the content inside build directory to public_html directory, and that's all, go to your domain and your app will be working just fine.

Tags:

Reactjs