0

I'm getting an H10 error with my node app on Heroku. It was working fine until I added Google analytics to my EJS files. My env port is set fine, the only other thing I think it could be is my connection to my MongoDB database on MLab...

Here's the app file:

var express = require('express'),
app = express(),
router = express.Router(),
ejs = require('ejs'),
bodyParser = require('body-parser'),
passport = require('passport'),
LocalStrategy = require('passport-local'),
mongoose = require('mongoose'),
flash = require('connect-flash'),
methodOverride = require('method-override'),
Post = require('./models/post'),
helmet = require('helmet'),
Comment = require("./models/comment"),
Email = require("./ignore/email"),
Raph = require("./ignore/raphuser"),
User = require('./models/user'),
nodemailer = require('nodemailer');
postRoutes = require('./routes/posts');


app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(methodOverride("_method"));
app.set('view engine', 'ejs');

app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());


app.use('/api/posts', postRoutes);
app.use(helmet());
app.use(flash());

app.use(express.static(__dirname + '/views'));
app.use(express.static(__dirname + '/public'));

// then my routes

app.listen(process.env.PORT || 5000);

And also my connection to MLab:

var mongoose = require('mongoose');
mongoose.set('debug', true);
mongoose.connect("mongodb://myusername:mypassword@ds147390.mlab.com:47390/dbname");

mongoose.Promise = Promise;

module.exports.Post = require('./post');

Raph117
  • 3,441
  • 7
  • 29
  • 50
  • Can you show the error message and also add a callback console.log to your mongoose connect function? – mxdi9i7 Sep 27 '18 at 21:14
  • yep two secs..... – Raph117 Sep 27 '18 at 21:18
  • How would I do the callback properly? I'm doing this to try and getting work, but getting an unhandled error back: mongoose.connect("mongodb://user:pw@ds147390.mlab.com:47390/personal_blog_posts", function(error, db){ if (error) { console.log(err) } else { return db; } }); – Raph117 Sep 27 '18 at 21:21
  • `var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:')); db.once('open', function() { console.log('Connected to database was successful!') });` – mxdi9i7 Sep 27 '18 at 21:23
  • Hi I got it going, here's the error message 2018-09-27T21:23:05.656321+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=www.raphael-hetherington.com request_id=ee2401bb-8fdf-4566-bcee-01abbc58bf63 fwd="37.228.225.172" dyno= connect= service= status=503bytes= protocol=http 2018-09-27T21:23:11.380853+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=www.raphael-hetherington.com request_id=72dfebe9-82ae-46c0-b493-1c85ccc63df6 fwd="66.85.140.125" dyno= connect= service= status=503 bytes= protocol=http – Raph117 Sep 27 '18 at 21:24
  • From what I see the error is about a missing favicon file. Do you have a favicon file in the root directory? – mxdi9i7 Sep 27 '18 at 21:25
  • there is no problem when I run it on a local server - it connets to mlab fine... there's something causing the issue when I push to heroku – Raph117 Sep 27 '18 at 21:25
  • Can you try `heroku restart` – mxdi9i7 Sep 27 '18 at 21:26
  • the favicon is in my img directory in the public folder, which is given a relative path because I set it in the app.js – Raph117 Sep 27 '18 at 21:26
  • heroku restart didn't work :( – Raph117 Sep 27 '18 at 21:27
  • This may be a duplicated question, check this link: https://stackoverflow.com/questions/15693192/heroku-node-js-error-web-process-failed-to-bind-to-port-within-60-seconds-of – mxdi9i7 Sep 27 '18 at 21:28
  • I've got my port set like this: – Raph117 Sep 27 '18 at 21:32
  • var port = process.env.PORT || 5000; app.listen(port, "0.0.0.0", function(){ console.log('app is running on port: ', port); }); – Raph117 Sep 27 '18 at 21:32
  • thanks for the help - I think it is to do with the ports... – Raph117 Sep 27 '18 at 21:32

0 Answers0