text: const path = require('path');
  const express = require('express');
  const { errorHandler } = require('./middleware/errorMiddleware');
  const connectDB = require('./config/db');
  
  connectDB();
  
  const port = process.env.PORT || 5000;
  
  const app = express();
  
  app.use(express.json());
  app.use(express.urlencoded({ extended: false }));
  
  app.use('/api/goals', require('./routes/goalRoutes'));
  app.use('/api/users', require('./routes/userRoutes'));
  
  // Serve frontend
  if (process.env.NODE_ENV === 'production') {
    app.use(express.static(path.join(__dirname, '../frontend/build')));
  
    app.get('*', (_req, res) => {
      res.sendFile(
        path.resolve(__dirname, '../', 'frontend', 'build', 'index.html'),
      );
    });
  } else {
    app.get('/', (_req, res) => {
      res.send('Server is not running in production mode');
    });
  }
  
  app.use(errorHandler);
  
  app.listen(port, () => console.log(`Server started on port ${port}`));
  