text: const express = require('express');
  const cors =require('cors');
  require('dotenv').config()
  const bodyParser = require('body-parser');
  const mongoose = require('mongoose');
  
  // route imports
  const userRoutes = require('./routes/userRoutes');
  const courseRoutes = require('./routes/courseRoutes');
  
  
  const { PORT } = process.env 
  const { WELCOME_MESSAGE, DATABASE_URL } = process.env
  
  
  // declare app isntance
  const app = express();
  const corsOptions ={
      origin:'*', 
      credentials:true,            //access-control-allow-credentials:true
      optionSuccessStatus:200,
   }
  // load middleware
  app.use(cors(corsOptions))
  app.use(bodyParser.json())
  app.use(bodyParser.urlencoded({extended: true }))
  
  
  
  // load routes to app
  app.use('/auth', userRoutes)
  app.use('/', courseRoutes)
  
  // spin up the server 
  mongoose.connect(DATABASE_URL).then(() => {
      // successful connection
      app.listen(PORT, ()=> {
          let message = `${WELCOME_MESSAGE} http://localhost:${PORT}`
          console.log(message)
      })
  }).catch(error => {
      console.error("Failed to start the server due to : ",error)
  })
  