{"size": 612, "ext": "js", "max_stars_repo_path": "server.js", "max_stars_repo_name": "Kisfejes/test-sequelize", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server.js", "max_issues_repo_name": "Kisfejes/test-sequelize", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server.js", "max_forks_repo_name": "Kisfejes/test-sequelize", "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": 18.5454545455, "max_line_length": 59, "alphanum_fraction": 0.5849673203}
const http = require('http');
const express = require('express');

const { initDB, closeDB } = require('./db/db');

async function initServer() {
  try {
    await initDB();

    const port = 7878;
    const app = express();

    const endpointRoutes = require('./endpoints');
    app.use(endpointRoutes);

    app.use('/', (req, res) => {
      res.status(404).send('Endpoint not found');
    });

    http.createServer(app);

    app.listen(port, () => {
      console.log(`Server listening on localhost:${port}`);
    });
  } catch (error) {
    console.log(error);
    await closeDB();
  }
}

initServer();

