This repository was archived by the owner on Nov 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (35 loc) · 1.27 KB
/
Copy pathserver.js
File metadata and controls
40 lines (35 loc) · 1.27 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
import mongoose from 'mongoose';
import app from './app.js';
// import glob from 'glob';
// import path from 'path';
/* Make sure it is node 10.0+ */
const [major, minor] = process.versions.node.split(".").map(parseFloat);
if (major < 10 || (major === 10 && minor <= 0)) {
console.log(
`Please go to nodejs.org and download version 10 or greater. 👌\n `
);
process.exit();
}
mongoose.connect(app.get("CONN"),
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true, // https://stackoverflow.com/a/51962721/10582082
useFindAndModify: false,
// "auth": { "authSource": "admin" },
// "user": "laxzadmin",
// "pass": "laxzsecret"
})
.then(() => console.log("DB is connected."))
.catch((err) => console.log('MongoDB connection error: ', err));
mongoose.Promise = global.Promise; // Tell Mongoose to use ES6 promises
mongoose.connection.on("error", (err) => {
console.error(`🚫 Error → : ${err.message}`);
});
// glob.sync(path.join(__dirname, './models/*.js')).forEach((file) => {
// require(path.resolve(file));
// });
const PORT = app.get("PORT") || 6969; /* 6969 is an error 👻 */
app.listen(PORT, () => {
console.log(`🚀 Server is listening on port ${PORT}`);
});