-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
46 lines (36 loc) · 1.12 KB
/
index.js
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
/**
*
* Author: George Simos - georgesimos.com
*
* License: Copyright (c) 2019 George Simos
* @link https://github.com/georgesimos/nodejs-mvc-starter
*
*/
import express from 'express';
import logger from 'morgan';
import dotenv from 'dotenv';
import expressStatusMonitor from 'express-status-monitor';
import connectDB from './src/config/mongoose';
import routes from './src/routes';
// Make all variables from our .env file available in our process
dotenv.config({ path: '.env.example' });
// Init express server
const app = express();
// Connect to MongoDB.
connectDB();
// Middlewares & configs setup
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.disable('x-powered-by');
app.use(expressStatusMonitor());
app.use((req, res, next) => {
res.locals.user = req.user;
next();
});
// Here we define the api routes
app.use(routes);
const port = process.env.PORT || 8080;
const address = process.env.SERVER_ADDRESS || 'localhost';
app.get('/', (req, res) => res.send('Hello World!'));
app.listen(port, () => console.log(`Server running on http://${address}:${port}`));