text: const express = require('express');
  const morgan = require('morgan');
  const bodyParser = require('body-parser');
  const cookieParser = require('cookie-parser');
  const expressValidator = require('express-validator');
  const mongoose = require('mongoose');
  const fs = require('fs');
  const cors = require('cors');
  const dotenv = require('dotenv');
  dotenv.config();
  const app = express();
  
  // DB Config
  mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true })
    .then(() => {
      console.log('DB Connected!')
    });
  
  mongoose.connection.on('error', err => {
    console.log(`DB Connection Error: ${err.message}`)
  });
  
  // Get Routes
  const postRoutes = require('./routes/post');
  const authRoutes = require('./routes/auth');
  const userRoutes = require('./routes/user');
  
  // API Docs
  app.get('/', (req, res) => {
    fs.readFile('docs/apiDocs.json', (err, data) => {
      if (err) {
        res.status(400).json({ error: err });
      }
      const docs = JSON.parse(data);
      res.json(docs);
    })
  });
  
  // Middleware
  app.use(morgan('dev'));
  app.use(bodyParser.json());
  app.use(cookieParser());
  app.use(expressValidator());
  app.use(cors());
  
  app.use('/', postRoutes);
  app.use('/', authRoutes);
  app.use('/', userRoutes);
  app.use(function (err, req, res, next) {
    if (err.name === 'UnauthorizedError') {
      res.status(401).json({ error: 'Unauthorized, invalid token!' });
    }
  });
  
  const PORT = process.env.PORT || 3300;
  app.listen(PORT, () => {
    console.log(`App listening on port: ${PORT}`)
  });