{"size": 859, "ext": "js", "max_stars_repo_path": "app.js", "max_stars_repo_name": "Zarif-Karim/Task-Manager", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app.js", "max_issues_repo_name": "Zarif-Karim/Task-Manager", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app.js", "max_forks_repo_name": "Zarif-Karim/Task-Manager", "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": 23.8611111111, "max_line_length": 68, "alphanum_fraction": 0.6786961583}

const express = require('express');
const app = express();
const not_found = require('./middleware/not-found');
const error_handler = require('./middleware/error-handler');
//database connection
const connectDB = require('./connect');
//environment variables
require('dotenv').config();

//user defined constants
const PORT = 5000;

//routes
const task = require('./routes/task');

//middlewares
app.use(express.static('./static'));
app.use(express.json());

app.use('/api/v1/tasks', task);

app.use(not_found);
app.use(error_handler);

const start_server = async (port, db_connection) => {
    try{
        await connectDB(db_connection);
        //start server
        app.listen(port,()=>console.log(`http://localhost:${port}`))
    } catch (error) {
        console.log('Failed to start server', error);
    }
}

start_server(PORT,process.env.MONGO_URI);