-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
22 lines (17 loc) · 724 Bytes
/
server.js
File metadata and controls
22 lines (17 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const mongoose = require("mongoose");
// Load environment variables from .env file if not in production
if (process.env.NODE_ENV !== "production") {
require("dotenv").config();
}
// Set `strictQuery: false` to globally opt into filtering by properties that aren't in the schema
// Included because it removes preparatory warnings for Mongoose 7.
mongoose.set("strictQuery", false);
// Define the database URL to connect to.
const mongoDB = process.env.MONGODB_URI;
// Wait for database to connect, logging an error if there is a problem
main().catch((err) => console.log(err));
async function main() {
await mongoose.connect(mongoDB);
console.log(`connected to database`);
}
module.exports = mongoose.connection;