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 :: what are native node modules 
Javascript :: latin science words 
Javascript :: nodejs catch uncaught exception 
Javascript :: react useref 
Javascript :: how to validate the radio button using jquery 
Javascript :: javascript trigger change event 
Javascript :: xmlhttprequest error handling 
Javascript :: js math.random 
Javascript :: how to create a form without a submit button javascript 
Javascript :: Internet Speed Checker JavaScript 
Javascript :: concat object 
Javascript :: api testing 
Javascript :: angular wait all subscriptions 
Javascript :: bootbox js confirmation 
Javascript :: react background image opacity 
Javascript :: rounding up a number so that it is divisible by 5 javascript 
Javascript :: javascript object to query params 
Javascript :: assign class to element javascript 
Javascript :: insert new object values 
Javascript :: javascript array reorder elements 
Javascript :: .children javascript 
Javascript :: javascript array to string 
Javascript :: append a query string to the url react 
Javascript :: javascript create array of objects from multiple arrays 
Javascript :: how to delete a reply in discord.js 
Javascript :: javascript get class name 
Javascript :: how to push string into array in javascript 
Javascript :: jquery datatable get column values in array 
Javascript :: reverse int js 
Javascript :: js foreach 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =