{"size": 1830, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "todtsies/Four-Paws-Best-Buddies", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "index.js", "max_issues_repo_name": "todtsies/Four-Paws-Best-Buddies", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "index.js", "max_forks_repo_name": "todtsies/Four-Paws-Best-Buddies", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.7272727273, "max_line_length": 81, "alphanum_fraction": 0.5830601093}
import express from 'express';
// import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import cors from 'cors';

import { MONGODB_URI } from './config/dev.js';
import path from 'path';
// import { dirname } from 'path';
// import { fileURLToPath } from 'url';

import postRoutes from './routes/posts.js';
import userRoutes from './routes/user.js';

const app = express();

app.use(express.json({ limit: "30mb", extended: true }));
app.use(express.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());

app.use('/posts', postRoutes);
app.use('/user', userRoutes);

const PORT = process.env.PORT || 5000;

// const __dirname = dirname(fileURLToPath(import.meta.url)); 

if (process.env.NODE_ENV === "production") {
  mongoose.connect(MONGODB_URI,
      { useNewUrlParser: true,
      useUnifiedTopology: true
      })
      mongoose.connection.on('connected',()=>{
          console.log('connected to db')
      })
      mongoose.connection.on('error',(err)=>{
          console.log('err connecting', err)
      })
      mongoose.set('useFindAndModify', false);
      
      app.use(express.static("client/build"));
      app.get('*', (req, res) => {
          res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));

      });
    }   

     else {
        mongoose.connect(MONGODB_URI,
               { useNewUrlParser: true,
               useUnifiedTopology: true
               })
               mongoose.connection.on('connected',()=>{
                   console.log('connected to db')
               })
               mongoose.connection.on('error',(err)=>{
                   console.log('err connecting', err)
               })
               mongoose.set('useFindAndModify', false);
         }

    app.listen(PORT, () => console.log(`Server is running on port: ${PORT}`))




