iposton / react-chat

react chat app

Home Page:https://new-parent-chat.herokuapp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New Parent Chat React, Heroku - Demo

Description

This is a single page app which uses socket.io to allow chat messages to post immediately to the page when send is clicked.

You can learn this

  • Create a chat app with react and socket.io.
  • 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.

  • First I went to Create React App and followed the instructions in the readme.
  • After create 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.

About

react chat app

https://new-parent-chat.herokuapp.com/


Languages

Language:JavaScript 78.6%Language:HTML 14.0%Language:CSS 7.4%