-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
28 lines (27 loc) · 917 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import app from "./server.js";
import mongodb from "mongodb";
import dotenv from "dotenv";
import MoviesDAO from "./dao/moviesDAO.js";
import ReviewsDAO from "./dao/reviewsDAO.js";
async function main() {
dotenv.config();
const uri = process.env.MOVIEREVIEWS_DB_URI;
const client = new mongodb.MongoClient(uri);
const port = process.env.PORT || 8000;
try {
// Connect to the MongoDB cluster
console.log("Connecting to MongoDB...")
await client.connect();
await MoviesDAO.injectDB(client);
await ReviewsDAO.injectDB(client);
console.log("Connected to MongoDB!")
// Launch the server
console.log("Launching server...")
await app.listen(port, () => { console.log(`Listening on port ${port}`); });
} catch (e) {
console.error(e);
process.exit(1);
}
}
main().catch(console.error);
// export default main;