mysqlnode.jsexpressherokuclever-cloud

NodeJS API working locally but not on Heroku


So, I have a MERN App (M -> MySQL) and I deployed my MySQL DB on clever-cloud.
I replaced the respective fields (host, user, password and database) with the values I got from clever-cloud and the db is working fine (tested on Workbench and by running the backend server locally).
Now, when I deploy my NodeJS API to Heroku, all I can access is the "/" route, all other routes give a 404. I added all the env variables via the Heroku Dashboard. I am unable to figure out why this is happening.

My MySQL connection looks like this:

const connection = mysql.createConnection({
  host: <the host address I got from clever-cloud>,
  user: process.env.MYSQL_REMOTE_USER,
  password: process.env.MYSQL_REMOTE_PASS,
  database: <the db name I got from clever-cloud>,
  timezone: "UTC+0"
});

My app.js

const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const cors = require("cors");
require("dotenv").config();
require("./db/db");

const fileupload = require('express-fileupload'); 


const indexRouter = require("./routes/index");
const studentRouter = require("./routes/students");
const teacherRouter = require("./routes/teachers");
const classroomRouter = require("./routes/classroom");
const timetableRouter = require("./routes/timetable");
const quizRouter = require("./routes/quiz");
const assignmentRouter=require("./routes/assignment");
const resourceRouter=require("./routes/resource")

const app = express();


app.use(fileupload({useTempFiles: true}))

app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(cors());
app.use(express.static(path.join(__dirname, "public")));

app.use("/", indexRouter);
app.use("/students", studentRouter);
app.use("/teachers", teacherRouter);
app.use("/classroom", classroomRouter);
app.use("/timetable", timetableRouter);
app.use("/quiz", quizRouter);
app.use("/assignment",assignmentRouter);
app.use("/resource", resourceRouter);

app.listen(process.env.PORT || "3001", () =>
{
    console.log("Connected.");
});


Solution

  • Deployed it successfully now. I was pushing to heroku master while being on some other branch while my own master was several commits behind where I was assuming it to be.

    It works fine now.