text: var express = require("express");
  var path = require("path");
  var cookieParser = require("cookie-parser");
  var logger = require("morgan");
  const cors = require("cors");
  require("dotenv").config();
  var indexRouter = require("./routes/index");
  var apiRouter = require("./routes/api");
  var apiResponse = require("./helpers/apiResponse");
  
  // const swaggerUi = require("swagger-ui-express");
  // swaggerDocument = require("./swagger.json");
  
  // DB connection
  // MONGO_CONNECTION_URL="mongodb+srv://ecom:ecomadmin@ecom.7hcok.mongodb.net/ecom?retryWrites=true&w=majority"
  var MONGODB_URL = process.env.MONGO_CONNECTION_URL;
  var mongoose = require("mongoose");
  mongoose.connect(MONGODB_URL, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => {
          //don't show the log when it is test
          if (process.env.NODE_ENV !== "test") {
              console.log("Connected to %s", MONGODB_URL);
              console.log("App is running ... \n");
              console.log("Press CTRL + C to stop the process. \n");
          }
      })
      .catch(err => {
          console.error("App starting error:", err.message);
          process.exit(1);
      });
  var db = mongoose.connection;
  
  var app = express();
  
  //don't show the log when it is test
  if (process.env.NODE_ENV !== "test") {
      app.use(logger("dev"));
  }
  
  app.use(express.json());
  app.use(express.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, "public")));
  
  // Swagger UI 
  // app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
  
  //To allow cross-origin requests
  app.use(cors());
  
  //Route Prefixes
  app.use("/", indexRouter);
  app.use("/api", apiRouter);
  
  // throw 404 if URL not found
  app.all("*", function(req, res) {
      return apiResponse.notFoundResponse(res, "Page not found");
  });
  
  app.use((err, req, res) => {
      if (err.name == "UnauthorizedError") {
          return apiResponse.unauthorizedResponse(res, err.message);
      }
  });
  
  module.exports = app;