text: const express = require('express');
  const mongoose = require('mongoose');
  const compression = require('compression');
  const bodyParser = require('body-parser');
  const passport = require('passport');
  const morgan = require('morgan');
  const cors = require('cors');
  const path = require('path');
  const dotenv = require('dotenv');
  const { ValidationError } = require('express-validation');
  
  const routes = require('./routes');
  const { port, mongoURI } = require('./config');
  
  dotenv.config();
  
  const app = express();
  
  app.use(cors());
  
  app.use(compression());
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(bodyParser.json());
  
  app.use(morgan('dev'));
  
  app.use(passport.initialize());
  app.use(passport.session());
  
  app.use('/api/v1', routes);
  
  app.use((err, req, res, next) => {
    if (err instanceof ValidationError) {
      return res.status(err.statusCode).json(err);
    }
  
    return res.status(err.status).json(err);
  });
  
  mongoose
    .connect(mongoURI, {
      useCreateIndex: true,
      useNewUrlParser: true,
      useUnifiedTopology: true,
    })
    .then(() => console.log('DB Connected'))
    .catch(e => console.log('DB Connection Error - ', e));
  
  if (process.env.NODE_ENV === 'production') {
    app.use(express.static('client/build'));
  
    app.get('*', (req, res) => {
      res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
    });
  }
  
  app.listen(port || 5000, () =>
    console.log(`Server is running at port ${port || 5000}`),
  );
  