const express = require("express");
const cors = require('cors');

const dotenv = require('dotenv');

if(process.env.NODE_ENV) {
  dotenv.config({
    path: `.env.${process.env.NODE_ENV}`
  });
} else {
  dotenv.config();
}

const app = express();
const connectDB = require("./db");

// connect database
connectDB();

app.use(cors({
  origin: 'http://localhost:3000',
  credentials: true, // if using cookies/auth
}));

app.get("/api/test", (req, res) => {
  console.log("Hey");
  res.json({"message": "Hello from backend!"});
});

app.listen(5000, () => {
  console.log("Server running on port 5000");
});