-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
26 lines (18 loc) · 732 Bytes
/
Copy pathserver.js
File metadata and controls
26 lines (18 loc) · 732 Bytes
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
require('dotenv').config({path: "./config.env"});
const express = require('express');
const connectDB = require('./config/db');
const errorHandler = require('./middleware/error');
// connect to the database
connectDB();
const PORT = process.env.PORT || 8080;
const app = express();
app.use(express.json());
app.use('/api/auth', require('./routes/auth'));
app.use('/api/private', require('./routes/private'));
// error handler should be the last piece of middleware
app.use(errorHandler);
const server = app.listen(PORT, () => console.log(`Server started on http://localhost:${PORT}`))
process.on("unhandledRejection", (err, promise) => {
console.log(`Logged Error: ${err}`);
server.close(() => process.exit(1));
});