Git Product home page Git Product logo

spool's Introduction

Create React App, Heroku - Demo

Description

This is the create react app live on heroku using node.js and express server.

You can learn this

  • Deploy a create react app to Heroku.

Software used for this application

Clone and serve this app.

  • First npm install then run npm start. (may need to have npm version 5.2+ installed on your machine)

Deploy create react app to Heroku.

  • Go to Create React App and follow the instructions in the readme.
  • cd app-name into app npm run-script build to build the app in a build directory.
  • Create an app.js file touch app.js.
  • For Heroku this app points to the app.js server which uses node.js and express. (node.js is required to serve locally)
//app.js

const express = require('express');
const http = require('http');
const path = require('path');

var app = express();

app.use(express.static(path.join(__dirname, 'build')));

const port = process.env.PORT || '8080';
app.set('port', port);

const server = http.createServer(app);
server.listen(port, () => console.log(`Running on localhost:${port}`));
  • Run node app.js to serve the app at http://localhost:8080.
  • Run touch Procfile in this app's root specifies the server for heroku to use.

//Procfile

web: node app.js

  • Run npm install express --save.
  • A few adjustments to package.json are necessary for the heroku deploy process. postinstall and engines are important parts of package.json for a successful deploy.
//package.json

{
  "name": "app-name",
  "version": "0.1.0",
  "private": true,
  "main": "app.js",
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "postinstall": "react-scripts build"
  },
  "engines": {
    "node": "~6.10.3",
    "npm": "~5.6.0"
  },
  "dependencies": {
    "express": "^4.16.3",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-scripts": "1.1.1",
  }
}
  • Assuming the heroku account is created and heroku toolbelt is installed make an initial commit and push to a github repo, then login to heroku, create a heroku app and push to heroku. Steps as follow.
  • git commit -am "initial commit" then git push. (pushing app to new github repo)
  • Login to heroku heroku login enter heroku password.
  • Create heroku app heroku create app-name. (this will add the heroku remote)
  • Deploy to heroku git push heroku master.

There may be an error during deploy pertaining to package.lock and yarn.lock. Delete yarn.lock from the app, commit and push to github repo and then git push heroku master again and the error will go away.

Each time there is a change to the app commit and push to github then git push heroku master to keep the two master branches in sync.

spool's People

Contributors

abimaell95 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.