my capstone project

// Import required libraries
const express = require(‘express’);
const cors = require(‘cors’);
const mongoose = require(‘mongoose’);
const taskRoutes = require(‘./routes/taskRoutes’);
const userRoutes = require(‘./routes/userRoutes’);
const auth = require(‘./config/auth’);
const database = require(‘./database’);

// Create an Express app
const app = express();

// Enable CORS
app.use(cors());

// Parse JSON requests
app.use(express.json());

// Use task routes
app.use(‘/tasks’, taskRoutes);

// Use user routes
app.use(‘/users’, userRoutes);

// Authenticate routes
app.use(auth.authenticate);

// Port number
const PORT = process.env.PORT || 3000;

// Start the server
app.listen(PORT, () => {
console.log(Server started on port ${PORT});
});

// Error handling
process.on(‘uncaughtException’, (err) => {
console.error(‘Uncaught exception:’, err);
process.exit(1);
});

// Close database connection on exit
process.on(‘exit’, () => {
mongoose.connection.close();
});