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

const app = express();

// Middleware
app.use(cors());
app.use(express.json());

// Import routes
const employeeRoutes = require("./routes/employee");
const departmentRoutes = require("./routes/department");
const salaryRoutes = require("./routes/salary");

// Use routes
app.use("/employees", employeeRoutes);
app.use("/departments", departmentRoutes);
app.use("/salary", salaryRoutes);

// Connect database
mongoose.connect("mongodb://127.0.0.1:27017/epms")
.then(() => console.log("Database Connected"))
.catch(err => console.log(err));

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