if(process.env.NODE_ENV=='development'){
    require('dotenv').config();
    console.log('Ejecutando en modo: ',process.env.NODE_ENV)
  }
  else{
    console.log('Ejecutando en modo: ',process.env.NODE_ENV)
  
  }

const express = require('express');
const mongoose = require('mongoose');
const morgan = require("morgan")
const colors = require('colors')
const cors = require('cors')
const app = express();

// express config
app.use(morgan("tiny"));
app.use(express.json());
app.use(express.urlencoded({
    extended:true
}));
app.set('port',process.env.PORT || 4000);
app.use(cors());

//Rutas
app.use('/api',require('./routes/users'));
app.use('/api',require('./routes/compras'))
app.use('/api',require('./routes/categorias'))
app.use('/api',require('./routes/metodos_pago'))
module.exports = app;

app.listen(app.get('port') ,() => console.log("service startes, listening on the port: ",app.get('port')))


//Mongo conecction

var uri;
if(process.env.NODE_ENV=='development'){

    uri=process.env.MONGOOSE_URI_LOCAL

}
else{

    uri=process.env.MONGOOSE_URI_PRODUCCION

}



const options={
    useNewUrlParser:true,
    useCreateIndex:true,
    useUnifiedTopology:true,
    authSource:"admin"
};

const db = mongoose.connect(uri,options).then(()=>{

        console.log("Successful connection to Mongo".green);
    },(err)=> console.log(`Fail conecction to Mongo: ${err}`.red));
    

