const express = require("express");
const cors = require("cors");
const app = express();
app.use(express.json());
app.use(cors());

var mysql = require("mysql2");
const connection = mysql.createPool({
  host: "109.106.254.1",
  user: "u353443769_beis",
  password: "testadmin",
  database: "u353443769_beis",
  waitForConnections: true,
  multipleStatements: true,
  connectionLimit: 10,
  maxIdle: 10, // max idle connections, the default value is the same as connectionLimit
  idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000
  queueLimit: 0,
});

app.get("/categories", (req, res) => {
    connection.query("SELECT dg_category_name FROM categories", (error, result) => {
      res.send(result);
    });
  });

  app.listen(3000, (err) => {
    if (err) {
      console.log(err);
    } else {
      console.log("listening on port 3000");
    }
  });