0

I really don't understand why this is occuring. I can create pool connections no problem without the use of app.use(express'static('public')); - the results show up in the Heroku console. However, when I include this line to serve static files - nothing occurs in console. I am using Heroku - is it possible that this may be part of the issue? Or is this something obvious about Express that I'm missing?

var express = require('express');
var app = express();
var fs = require('fs');
var path = require('path');
var mysql = require('mysql');



 var pool = mysql.createPool({
 
      connectionLimit: 10,
      host:'*******',
      user:'*******',
      password:'*******',
      database:'*******'
    });





app.use(express.static('public'));


 app.get('/',function(req,res){

 pool.query("*********", function(err, rows, fields) {
    if (err) throw err;
  console.log(rows[0]);
    });
});

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

Project is stored as public/index.html with files in sub-directories.

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
  • In my opinion, Heroku couldn't be the cause of this. However, if you're not sure, can't you try this code on localhost, or another not-Heroku server to see if the logs will be printed in the console ? – Son Huy TRAN Aug 08 '17 at 13:48
  • Apologies - the logs work when app.get is removed. However that's not ideal as it only does a database call on app startup. - I need a database call on every instance of homepage load. Why does app.use stop app.get from working? Is there another method I am missing? – Roger Rovenfelds Aug 08 '17 at 14:01
  • 1
    Figured it out - it's the index.html call. Made an index: false and then sendfile after the database calls - wish I found that answer earlier!! – Roger Rovenfelds Aug 08 '17 at 14:22
  • I don't think so, your code should working without any problem, except that maybe there is an index file in your public folder, then there is a conflict between this index file and app.get('/'). Because the server does not know that it should return the index file or execute the request handler. – Son Huy TRAN Aug 08 '17 at 14:23
  • Ah we just found out it at the same time, great! :) – Son Huy TRAN Aug 08 '17 at 14:24

0 Answers0