How to deploy react app with express js(SSR)

deploy react app with express js(SSR)

Deploy your reactjs application with expressjs backend. SSR server side rendering with expressjs and reactjsHow to deploy react app with express js(SSR)

this 

dsad

There is 2 ways you can deploy react app in production.

we focus on server-side rendering with expressjs backend

1. Using static server

create a build of react app and serve it statically using serve command. 

2. Serve page from expressjs

You don’t necessarily need a static server in order to run a Create React App project in production. It also works well when integrated into an existing server side app.

first you need to build your react code using:

npm run build

const express =require('express');
const path =require('path');
const app =express();

app.use(express.static(path.join(__dirname,'build')));
//setting static path
app.get('/',function(req, res){
  res.sendFile(path.join(__dirname,'build','index.html'));
});

app.listen(4000);

after getting build of your react code 

app.use(express.static(path.join(__dirname,’build’)));

serve the build folder as static files, and target the index.html inside it

app.get(‘/’,function(req, res){

res.sendFile(path.join(__dirname,’build’,’index.html’));

});

this will redirect all the incomming request to index.html inside build directories. This is how react app can be deployed using reactjs.

Read blogs on

https://collegeinit.com/How-to-deploy-react-app-with-express-js(SSR)=5edf25b394d78926bf84bb85

Published by collegeinit

collegeinit is a web app connecting students and college.

Leave a comment

Design a site like this with WordPress.com
Get started