2021-05-06 20:03:31 +03:00
|
|
|
const express = require('express');
|
2021-05-10 18:47:26 +03:00
|
|
|
const { connectDB } = require('./db');
|
|
|
|
const errorHandler = require('./middleware/errorHandler');
|
2021-05-17 19:23:54 +03:00
|
|
|
const jobs = require('./utils/jobs');
|
2021-05-10 18:47:26 +03:00
|
|
|
const colors = require('colors');
|
2021-05-06 20:03:31 +03:00
|
|
|
require('dotenv').config();
|
|
|
|
|
2021-05-10 18:47:26 +03:00
|
|
|
connectDB();
|
|
|
|
|
2021-05-06 20:03:31 +03:00
|
|
|
const app = express();
|
|
|
|
const PORT = process.env.PORT || 5005;
|
|
|
|
|
|
|
|
app.get('/', (req, res) => {
|
2021-05-10 18:47:26 +03:00
|
|
|
res.send('Server is working');
|
2021-05-06 20:03:31 +03:00
|
|
|
})
|
|
|
|
|
2021-05-10 18:47:26 +03:00
|
|
|
// Body parser
|
|
|
|
app.use(express.json());
|
|
|
|
|
|
|
|
// Link controllers with routes
|
|
|
|
app.use('/api/apps', require('./routes/apps'));
|
2021-05-15 19:33:59 +03:00
|
|
|
app.use('/api/config', require('./routes/config'));
|
2021-05-17 19:23:54 +03:00
|
|
|
app.use('/api/weather', require('./routes/weather'));
|
2021-05-10 18:47:26 +03:00
|
|
|
|
|
|
|
// Custom error handler
|
|
|
|
app.use(errorHandler);
|
|
|
|
|
2021-05-06 20:03:31 +03:00
|
|
|
app.listen(PORT, () => {
|
2021-05-10 18:47:26 +03:00
|
|
|
console.log(`Server is running on port ${PORT} in ${process.env.NODE_ENV} mode`.yellow.bold);
|
2021-05-06 20:03:31 +03:00
|
|
|
})
|