{"size": 1147, "ext": "js", "max_stars_repo_path": "backend/seeder.js", "max_stars_repo_name": "HarshVerm/primevideo", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "backend/seeder.js", "max_issues_repo_name": "HarshVerm/primevideo", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "backend/seeder.js", "max_forks_repo_name": "HarshVerm/primevideo", "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.8958333333, "max_line_length": 60, "alphanum_fraction": 0.6320836966}
const express=require("express")
const mongoose = require("mongoose")
const dotenv = require("dotenv")
const mediaInfo=require("./data/mediaInfo")
const Media = require("./models/media")
const cors = require("cors")
const mediaRoute=require("./routes/media")
const connectDB=require("./config/db")

dotenv.config();
const app = express()
connectDB()
app.use(express.json())
app.use(cors())
app.use("/api/media", mediaRoute)
console.log(Media[0])

const importData = async () => {
    try {
        await Media.deleteMany()
        const createdMedia=await Media.insertMany(mediaInfo)
        console.log("Data Import Successfull")
        process.exit()
    } catch (err) {
        console.log("Error: " + err.message)
        process.exit(1)
    }
}

const destroyData = async () => {
    try {
        await Media.deleteMany()
        console.log("Data Deletion Successfull")
        process.exit()
    } catch (err) {
        console.log("Error: " + err.message)
        process.exit(1)
    }
}

if(process.argv[2]==="-d"){
    destroyData()
}
else importData()

app.listen(8001, () => {
    console.log("The server is running on port 5000")
})