Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

create react app deployment heroku

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
Comment

Deploy React and Express to Heroku

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}`);
Comment

PREVIOUS NEXT
Code Example
Javascript :: java script alerts 
Javascript :: react rating 
Javascript :: express example 
Javascript :: crone expression in spring boot 
Javascript :: how to make popup modal in jquery with example 
Javascript :: map & filter 
Javascript :: word table to json 
Javascript :: open window in same tab 
Javascript :: Import A Module In ExpressJS 
Javascript :: js test library 
Javascript :: react onclick remove component 
Javascript :: nodejs date add days 
Javascript :: some in js 
Javascript :: js days to hours 
Javascript :: cookie-parser get cookie 
Javascript :: js chrome extension get current url 
Javascript :: js object delete value by key 
Javascript :: javascript this keyword 
Javascript :: what is react js 
Javascript :: http error 406 
Javascript :: js exports 
Javascript :: what is promise in javascript 
Javascript :: Return with an "IF" Statement 
Javascript :: jquery plugins 
Javascript :: mongoose query object 
Javascript :: heap javascript 
Javascript :: js append html in div after 
Javascript :: angular chart 
Javascript :: download in react 
Javascript :: passport jwt strategy 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =