Create React.js Hello World Web App and Deploy to Heroku
In this video I create a React.js Hello World web app and deploy it to the Heroku online hosting platform.
Links to content:
VS Code download: https://code.visualstudio.com/download
Node.js download: https://nodejs.org/en/
Heroku Sign Up: https://signup.heroku.com/
Server.js code:
const express = require('express');
const favicon = require('express-favicon');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();
app.use(favicon(__dirname + '/build/favicon.ico'));
// the __dirname is the current directory from where the script is running
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, 'build')));
app.get('/ping', function (req, res) {
return res.send('pong');
});
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(port);