-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (34 loc) · 1.14 KB
/
server.js
File metadata and controls
41 lines (34 loc) · 1.14 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
41
const http = require('http');
const app = require('./app');
const mongoose = require('mongoose');
const { success, error } = require('consola');
const { connect } = require('mongoose');
require('dotenv').config()
const PORT = process.env.PORT || 5000;
const server = http.createServer(app);
// Mongoose uri credential *************************/
const DATABASE_URL = `mongodb+srv://${process.env.DB_USER}:${process.env.DB_PASS}@cluster0.7tcxm.mongodb.net/${process.env.DB_NAME}?retryWrites=true&w=majority`
const startApp = async () => {
try {
// Connection With DB
await connect(DATABASE_URL)
success({
message: `Successfully connect with the Database \n${DATABASE_URL}`,
badge: true
});
// Start Listening for the server on PORT
server.listen(PORT, () =>
success({
message: `Server started on PORT ${PORT}`,
badge: true
})
);
} catch (err) {
error({
message: `Unable to connect with Database \n${err}`,
badge: true
});
}
}
mongoose.Promise = global.Promise;
startApp();