0

i have different node, here my package.json

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"node_1": "nodemon --watch dev -e js dev/networkNode.js 3001 http://localhost:3001",
"node_2": "nodemon --watch dev -e js dev/networkNode.js 3002 http://localhost:3002",
"node_3": "nodemon --watch dev -e js dev/networkNode.js 3003 http://localhost:3003",
"node_4": "nodemon --watch dev -e js dev/networkNode.js 3004 http://localhost:3004",
"node_5": "nodemon --watch dev -e js dev/networkNode.js 3005 http://localhost:3005"
},

In my local env i run:

npm run node_1 
npm run node_2 
npm run node_3 
npm run node_4
npm run node_5

And the node are accessibile in http://localhost:300X url.

Now i want to deploy on Heroku my prototype.

if i put:

"node_1": "nodemon --watch dev -e js dev/networkNode.js 3001 https://my-heroku-app.herokuapp.com:3001",

And then i go to:

https://my-heroku-app.herokuapp.com:3001

The app doesn't open, but the build is success.

I tried:

  • Create Procfile: web: npm run node_1

-Running via Heroku Cli heroku run npm run node_1

Not works...

How can i set this node on heroku?

Riccardo Mel
  • 121
  • 10

2 Answers2

0

What you are trying to do is not possible on Heroku. A deployed App on Heroku is assigned only one port. Furthermore you cannot specify the port. It is supplied to you by Heroku via the environment variable $PORT.

Tin Nguyen
  • 5,250
  • 1
  • 12
  • 32
  • It is possible in some other platform similar to heroku? – Riccardo Mel Mar 17 '20 at 11:17
  • I would go straight for a VPS. Solutions like Heroku doesn't make it easier. Heroku is easy for the end user but not for a developer. AWS, Digital Ocean (GitHub education pack), Google Cloud Compute also have a free tier solution although often time limited. – Tin Nguyen Mar 17 '20 at 12:18
0

@Tin Nguyen answer is not exact. On Heroku it's mandatory to bind something on $PORT, but then you can bins something else to some other port. See https://devcenter.heroku.com/articles/dynos#web-dynos

Also see How to run Django and node.js app on same dyno in Heroku? for how to run multiple backends on a dyno and let them communicate. It makes the case with Django+Node, but it can be used with Node+Node as well.