1

I'm having issue connecting to my very first Nodejs app in Heroku. No issue running on local, and no issue when executing heroku local web. But when I tail the logs, it says:

2019-05-28T02:32:49.911060+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=myveryfirst.herokuapp.com request_id=1df1314a-bf72-4201-8b20-fb812088e633 fwd="219.92.3.81" dyno= connect= service= status=503 bytes= protocol=https

I've setting up the Procfile:

> web: node ./src/server.js

Here my package.json:

{
  "name": "myveryfirst",
  "version": "1.0.0",
  "description": "",
  "main": "./src/server.js",
  "engines": {
    "node": "10.15.0",
    "npm": "6.4.1"
  },
  "directories": {
    "test": "test"
  },
  "scripts": {
    "test": "jest --watch --runInBand",
    "start": "node ./src/server.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/lola/myveryfirst.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/lola/myveryfirst/issues"
  },
  "homepage": "https://github.com/lola/myveryfirst#readme",
  "dependencies": {
    "body-parser": "^1.19.0",
    "cls-hooked": "^4.2.2",
    "dotenv": "^8.0.0",
    "express": "^4.17.1",
    "express-session": "^1.16.1",
    "joi": "^14.3.1",
    "js-sha512": "^0.8.0",
    "mongoose": "^5.5.11",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0",
    "path": "^0.12.7",
    "pug": "^2.0.3",
    "uuid": "^3.3.2",
    "winston": "^3.2.1"
  }
}

Here's my server.js

const express = require('express');
const cls = require('cls-hooked');
const db = require('./config/mongodb');
const passport = require('passport');
const session = require('express-session');
const config = require('./config/config');
const router = require('./routes/router');
const clsBinder = require('./middleware/clsBinder');
const logFormatter = require('./middleware/logFormatter');
const logger = require('./services/loggerService');
const path = require('path');
const bodyParser = require('body-parser');

// Initialize the express application
const app = express();

// Create a cls namespace for the correlation ID
const ns = cls.createNamespace(config.cls.correlationIdNamespace);

app.use(clsBinder(ns));
app.use(logFormatter);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// Assign passport to express
require('./config/passport')(passport);

app.use(session({
  // cookie: { maxAge: 60000 },
  secret: config.sessionSettings.secret,
  resave: false,
  saveUninitialized: false,
}));
app.use(passport.initialize());
app.use(passport.session());

// Load View Engine
app.use(express.static('./'));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

// Body Parser Middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));

// Assign the routes to express
app.use(router);

app.use((err, req, res) => {
  logger.error(err);
  res.send({ error: err.message });
});

// Connecting to DB
db();

// Start the server
app.server = app.listen(process.env.PORT || 3000, (err) => {
    if (err) {
        logger.error(err);
    }
  logger.info(`Server started successfully`);
});

module.exports = app;
Rudy Reus
  • 51
  • 6
  • https://stackoverflow.com/questions/14322989/first-heroku-deploy-failed-error-code-h10 This link may helps you – Ameerudheen.K May 28 '19 at 03:44
  • I've tried to set the node and npm version in my package.json, have tried to edit my procfile accordingly, have configuring .env variable to the Heroku config var settings, but im not sure if password that contain '%' cause an issue. Please advise – Rudy Reus May 28 '19 at 04:17

0 Answers0