{"size": 1059, "ext": "js", "max_stars_repo_path": "app.js", "max_stars_repo_name": "anurag-0071/libraryApp", "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": "anurag-0071/libraryApp", "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": "anurag-0071/libraryApp", "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.0217391304, "max_line_length": 65, "alphanum_fraction": 0.6071765817}
const express = require("express");
const http = require('http');
const Mongoose = require('mongoose');
const readline = require('readline');

const DB_URL = 'mongodb://localhost/libraryapp';
const PORT = 8080;

const books = require("./router/books");
const cardHolder = require("./router/cardHolder");
const rental = require("./router/rental");

const app = express();

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

app.use(express.json());

app.use('/books', books);
app.use('/cardHolder', cardHolder);
app.use('/rental', rental);

const startServer = () => {
  Mongoose.connect(DB_URL, (err) => {
    if (!err) {
      http.createServer(app).listen(PORT, () => {
        console.log("Server started on port:", PORT);
      });
    } else {
      console.error("Error in mongoose connection", err.message);
      rl.question("Type `rs` to restart server", (answer) => {
        if (answer === 'rs') {
          startServer();
        } else {
          return;
        }
      })
    }

  });
}

startServer();