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: "127.0.0.1",
  user: "root",
  password: "",
  database: "kvalifikacija_dgusenkovs",
  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 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");
    }
  });