forked from Thiti-Dev/ScheduralizationV2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (37 loc) · 1.54 KB
/
server.js
File metadata and controls
49 lines (37 loc) · 1.54 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
42
43
44
45
46
47
48
49
const express = require('express');
const dotenv = require('dotenv');
const app = express();
const colors = require('colors');
const cookieParser = require('cookie-parser');
const errorHandler = require('./middleware/error');
//
// ─── UTILS ──────────────────────────────────────────────────────────────────────
//
const formattedLog = require('./utils/formatted-log');
// ────────────────────────────────────────────────────────────────────────────────
// importing database
const models = require('./models');
// Load env vars
dotenv.config({ path: './config/config.env' });
// Middlewares
app.use(express.json());
app.use(cookieParser());
// Importing route
const auth = require('./routes/api/auth');
// @Apply route
app.use('/api/auth', auth);
// @Error Hander
app.use(errorHandler);
// Establish the Sequelize connection with the database
models.sequelize
.authenticate()
.then(function() {
formattedLog.information(`Sequelize successfully connected`);
})
.catch(function(error) {
formattedLog.information('Error creating connection:', error);
});
const PORT = process.env.PORT || 5000;
const server = app.listen(PORT, () => {
formattedLog.information(`The server is currently running in ${process.env.NODE_ENV} mode on port ${PORT}`);
});