Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku: How to deploy a node app with client and server running on different ports?

I have a nodejs API as server and React/Redux app as client located in one git project: https://github.com/lafisrap/fcc_nightlife.git

I want to deploy it on Heroku using the heroku cli.

The scripts section in package.json is:

  "scripts": {
    "start-dev": "concurrently \"yarn run server\" \"yarn run client\"",
    "start": "yarn run server | yarn run client",
    "server": "babel-node server.js",
    "client": "node start-client.js",
    "lint": "eslint ."
  },

start-client.js:

const args = [ 'start' ];
const opts = { stdio: 'inherit', cwd: 'client', shell: true };
require('child_process').spawn('yarn', args, opts);

In the client folder I have another package.json which defines the client. The scripts section of it:

  "scripts": {
    "start": "react-scripts start",
  }

I did:

heroku create
git push heroku master

The api is running fine. But I don't know how to start/access the client.

like image 272
Michael Avatar asked Sep 01 '17 10:09

Michael


People also ask

How do I deploy a node app in Heroku?

Step 4: Deploying the Node.js app to HerokuClick on the “Create new app”. Open the Deploy tab and scroll to the “Deployment method” section of the tab. Select GitHub as a method. It will show a “Connect to GitHub” option where we add provide our GitHub repository.


1 Answers

You CAN NOT deploy two services in one Heroku app. In short, you have to deploy them to separate Heroku dynos to deploy two apps.

More information is provided in this stackoverflow answer to a similar question.

PS: It is always an option to serve JS files from your API server after building React files.

Hope this helps!

like image 194
tbking Avatar answered Sep 21 '22 20:09

tbking