status 503 when heroku node app try to access to mlab db add-on with monk

58 Views Asked by At

I'm trying to deploy my express-mongodb app on heroku. I've already tryed to access locally to the heroky mlab addon and with the local server works fine. But when I start the same server on heroku it looks like the server can't solve the requests because of the db lack. I'm wondering if the problem is with monk js or something else.




<!-- language: lang-javascript-->

const express = require('express');
    const bodyParser = require('body-parser');
    const monk = require('monk');
    const engines = require('consolidate');

    const app = express();

    const router = require('./routes/router');


    app.use(bodyParser.urlencoded({ extended: false }));

    app.use(express.static(`${__dirname}/public`));
    app.set('views', `${__dirname}/templates`);
    app.engine('html', engines.mustache);
    app.set('view engine', 'html');

    const db = monk('mongodb://<xxxx>.mlab.com:15338/heroku_1xx37v0b');
    db.then(() =>{
      console.log("connection success");
    }).catch((e)=>{
      console.error("Error !",e);
    });
    app.use((req, res, next) => { req.db = db; next(); });

    app.use('/', router);

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


    // ask something to the db
    const collection = db.get('docUtenti');
    collection.findOne({type: "docTotUtenti" }).then((doc) => {console.log(doc);})


0

There are 0 best solutions below