import dotenv from "dotenv";
dotenv.config();

import mongoose from "mongoose";
import app from "./app";

const PORT = process.env.PORT ?? 4000;
const MONGO_URI = `${process.env.MONGO_URI}`;

(async () => {
    try {
        await mongoose.connect(MONGO_URI);
        console.log("MongoDB conectada");
    } catch (err) {
        console.error("Error conectando MongoDB:", err);
        process.exit(1);
    }

    app.listen(PORT, () => {
        console.log(`Servidor corriendo en puerto ${PORT}`);
    });
})();
