Deploy React And Express To Heroku

[Solved] Deploy React And Express To Heroku | Javascript Frameworks Express - Code Explorer | yomemimo.com
Question : deploy react js heroku

Answered by : dangerous-duck

npm install -g create-react-app
create-react-app my-app
cd my-app
git init
heroku create -b https://github.com/mars/create-react-app-buildpack.git
git add .
git commit -m "react-create-app on Heroku"
git push heroku master
heroku open

Source : https://blog.heroku.com/deploying-react-with-zero-configuration | Last Update : Fri, 21 Feb 20

Question : Deploy React and Express to Heroku

Answered by : eugene-chiu

const express = require('express');
const path = require('path');
const generatePassword = require('password-generator');
const app = express();
// Serve static files from the React app
app.use(express.static(path.join(__dirname, 'client/build')));
// Put all API endpoints under '/api'
app.get('/api/passwords', (req, res) => { const count = 5; // Generate some passwords const passwords = Array.from(Array(count).keys()).map(i => generatePassword(12, false) ) // Return them as json res.json(passwords); console.log(`Sent ${count} passwords`);
});
// The "catchall" handler: for any request that doesn't
// match one above, send back React's index.html file.
app.get('*', (req, res) => { res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
const port = process.env.PORT || 5000;
app.listen(port);
console.log(`Password generator listening on ${port}`);

Source : https://www.codeproject.com/Articles/1238173/Deploy-React-and-Express-to-Heroku | Last Update : Wed, 06 Jul 22

Answers related to deploy react and express to heroku

Code Explorer Popular Question For Javascript Frameworks Express