1

I'm a Swift dev and not a native Node.js dev so I'm unfamiliar with this issue.

I signed up for Heroku, created an app, got the free dyno working and after the 450 hrs I got an email saying Your app(s) have stopped running and will not restart until you receive more free dyno hours next month.

I added my credit card for verification and got an additional free 550 hrs. I immediately got boosted back to 1000 free hours however once I did that the dyno never ran again.

Just now (a week later) I ran

heroku ps -a myAppName

and it says I have 1000 hrs.

Free dyno hours quota remaining this month: 1000h 0m (100%)
Free dyno usage for this app: 0h 0m (0%)

I just ran heroku ps:restart --app myAppName then checked back about 15 min later and it still says I used 0h 0m (0%)

I ran heroku logs --app myAppName and got these errors:

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

Stopping process with SIGKILL Process exited with status 137 State

changed from starting to crashed

Heroku says to change ports and add:

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
    console.log(`Our app is running on port ${ PORT }`);
});

Assuming this is the reason the dynos stopped working/sleeping, it seems (I'm unfamiliar with this) I need to add the port code to my app.js file? I don't know the modules to add in to get it to work. What do I add in to get the above port code working? For eg. what is app in the above code?

My procfile:

worker: node ./app.js

My app.js file

const dotenv = require('dotenv');
dotenv.config();

const admin = require("firebase-admin");
admin.initializeApp({
  credential: admin.credential.cert({
    projectId: process.env.FIREBASE_PROJECT_ID,
    clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
    privateKey: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n'),
  }),
  databaseURL: process.env.FIREBASE_DATABASE_URL
});

const firebase = require('firebase');
const config = {
    apiKey: process.env.FIREBASE_API_KEY,
    databaseURL: process.env.FIREBASE_DATABASE_URL,
    storageBucket: process.env.FIREBASE_STORAGE_BUCKET,GCM_SENDER_ID
};
firebase.initializeApp(config);

const algoliasearch = require('algoliasearch');
// rest of code ...

My package.json file:

{
  "name": "my project",
  "version": "1.0.0",
  "description": "Config Files",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js"
  },
  "author": "Lance Samaria",
  "license": "ISC",
  "engines": {
    "node": "10.16.0"
  },
  "dependencies": {
    "algoliasearch": "^3.35.1",
    "dotenv": "^8.2.0",
    "firebase": "^7.2.1",
    "firebase-admin": "^8.6.1",
    "nodejs-latest": "^1.1.0"
  }
}
Lance Samaria
  • 17,576
  • 18
  • 108
  • 256

1 Answers1

1

I did googling around here and here and found I had to install the express module. I used this answer

$ npm install --save express

Then in the top of the app.js file I added:

var express = require('express');
var app = express();

const PORT = process.env.PORT || 5000;

app.listen(PORT, () => {
  console.log(`Server is listening on port ${PORT}`);
});

Once I installed the above code the dynos started working again. I used 5000 instead of 3000 from here

Lance Samaria
  • 17,576
  • 18
  • 108
  • 256