-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (26 loc) · 936 Bytes
/
app.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
const express = require('express');
const mongoose = require('mongoose');
require('dotenv').config();
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const port = process.env.PORT || 3000;
mongoose.connect(process.env.MONGODB_URI,
{ useNewUrlParser: true, useUnifiedTopology: true });
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
db.once('open', () => {
console.log('Connected to MongoDB');
});
const authRoutes = require('./routes/authRoutes');
const imageRoutes = require('./routes/imageRoutes');
app.use('/auth', authRoutes);
app.use('/images', imageRoutes);
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Something went wrong!');
});
var server = app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});
module.exports = server