I have worked on VS Code to develop a react application that is using JSON server for backend. I wish to share the progress of my project with my team members so that they can access the project on their browser. I just want to generate a index.html file that I can share with others.
CodePudding user response:
Build your react project first with npm run build
.
Create one express server
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json());
app.listen(process.env.PORT, async () => {
console.log("listening on port " process.env.PORT);
});
Now serve your build folder as static file
const path = require("path");
app.use(express.static(path.join(__dirname, "build")));
Now go to http://localhost:<<PORT>>
and check if your website is running properly.
Now you can use ngrok to show demo to your friends. ngrok will allow you to host your site for some hours without any cost.
then run ngrok http <<PORT>>
and you can share this https url with your friends.
CodePudding user response:
Index.html and react app have different ways to deploy. If it is index.html use Github pages and you will get an URL to share with anyone.
If you use API endpoint:
- Push the code in Github and anyone will clone and check the app.
- Or npm run build and drag and drop the build app in Netlify or connect with Github repo.
If you don't use the API endpoint:
- Deploy your backend code in Heroku or another hosting site.
- You will get an endpoint after deploying in Heroku.
- Use the endpoint in your frontend instead of JSON data.
- Then deploy your front-end app [after building the app by npm run build]in Netlify, Vercel,... or other platforms and share the URL with anyone