How to deploy React app on heroku

How to deploy React app on heroku

Deployment of React Application on Heroku is very simple task. We can deploy React app on Heroku by many ways like Heroku CLI and Github.

Before deployement process we need to sure that our application should be in a production deployment mode.

Suppose we have created the build folder for production deployment. If still you have not created the build or deployment folder then we can create it by following cammands.

If you are using webpack then npm run build is the command for create the build files. We need to deploy only these build files to run our reat app with any backend server like express, hapi and other web servers.

If your application structure is like below format after create the build files.

 	/build 	/node_modules 	/public 	/src 	package.json 	README.md 

To deploy the React application we need a web server like express js.

So we need to install a express js framework to deploy the react app.

Create a package.json and server.js file to with express js framework.

package.json

 {   "name": "express-backend-server-for-react-app",   "version": "1.0.0",   "description": "Express Backend Deployment Server For React App",   "main": "server.js",   "scripts": {     "start": "node server.js"   },   "author": "Anil Kapoor",   "license": "ISC",   "dependencies": {     "express": "^4.16.2"   },   "engines": {     "node": "6.11.1",     "npm": "3.10.10"   } } 

server.js

 const express = require('express'); const app = express(); const path = require('path');  app.use(express.static(__dirname + '/build'));  app.listen(process.env.PORT || 8080);  app.get('/*', function(req, res){   res.sendFile(path.join(__dirname + '/build/index.html')); });  console.log('Server listening'); 

Now upload all these files on Github or use Heroku CLI to deploy directly. Here we will use git to upload all the files on github

 	/build 	package.json 	server.js 

Then we can deploy our React app with heroku. We need Heroku account and need to create our app with Heroku.

Security Checks in Node Js

Security Checks in Node Js

We can use lots of security check on node js for development and production environment. …

read more
What is scope in JavaScript

What is scope in JavaScript

What is scope in JavaScript …

read more