Unable to access API routes (Express)

Hello community!

I created a simple API locally which accesses a MySQL database also located locally. To try it in “production”, I dumped the database to Clever Cloud. I conducted some tests on my local API, accessing this database on Clever Cloud, and it worked out. I deployed the code here on Render, set environment variables, and it seems to have gone well. However, when I try to access some endpoints, it ends up with a timeout :frowning:

Here some code:

package.json

{
  "name": "bestbreedmatch-api",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon index.js",
    "start": "node index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.20.2",
    "express": "^4.18.2",
    "mysql2": "^3.2.3"
  },
  "devDependencies": {
    "nodemon": "^2.0.22",
    "dotenv": "^16.0.3"
  }
}

index.js (entry point in the the root of the project “/”)

// Environment
import _ from "./env.js";

import express from "express";

import { setLanguage } from "./src/middlewares/language.middleware.js";
import { requests } from "./src/middlewares/requests.middleware.js";

import indexRoutes from "./src/routes/index.routes.js";
import familiesRoutes from "./src/routes/families.routes.js";
import breedsRoutes from "./src/routes/breeds.routes.js";
import associationsRoutes from "./src/routes/associations.routes.js";
import traitsRoutes from "./src/routes/traits.routes.js";
import languagesRoutes from "./src/routes/languages.routes.js";
import bodyParser from "body-parser";

const app = express();
const port = process.env.PORT || 3000;
console.log("port:", port);

// Middlewares
app.use(setLanguage);
app.use(requests);

// Manage JSON responses
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// Routes
app.use(indexRoutes);
app.use(familiesRoutes);
app.use(breedsRoutes);
app.use(associationsRoutes);
app.use(traitsRoutes);
app.use(languagesRoutes);

app.listen(port, () => {
  console.log(`server listening on port ${port}`);
});

db.js (database connection in “/src/”:

import { createPool } from "mysql2/promise";

const { DB_HOST, DB_USER, DB_PASSWORD, DB_PORT, DB_NAME } = process.env;

const productionPoolData = `mysql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}`;

const poolData =
  process.env.NODE_ENV === "production"
    ? productionPoolData
    : {
        host: DB_HOST,
        user: DB_USER,
        password: DB_PASSWORD,
        port: DB_PORT,
        database: DB_NAME,
      };

console.log("poolData", poolData);
export const pool = createPool(poolData);

I guess I should access here: https://bestbreedmatch-api.onrender.com:10000/families

Any clue will be more than appreciated! Thanks beforehand :smiling_face:

BTW and example of a router

import { Router } from "express";
import {
  getFamilies,
  getFamily,
  createFamily,
  updateFamily,
  deleteFamily,
} from "../controllers/families.controllers.js";
const router = new Router();

router.get("/families", getFamilies);
router.get("/families/:id", getFamily);
router.post("/families", createFamily);
router.put("/families/:id", updateFamily);
router.delete("/families/:id", deleteFamily);

export default router;

Screenshot 2024-03-28 at 09.06.08

I’ve defined the node version I’m working locally as it says here Setting Your Node.js Version | Render Docs as well. But without results :confused:

Hi MRT07,

Can you clarify where the timeout is occurring is it?

Is it when you make a request to your API and your API is timing out? Or is it the request to the database that’s timing out?

If you could show an example (i.e. a curl request to your API, or logs from your service), including the timeout error, that would be a useful starting point.

Regards,

Matt