aboutsummaryrefslogtreecommitdiff
path: root/server/main.js
blob: ab7ce4d713ed43181c3d30e81b926d6ed50e3b37 (plain) (blame)
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
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const passport = require('passport');
const cors = require('cors');

const {port, mongoUrl} = require("./config/env");
const apiRoutes = require('./routes/api');

mongoose.connect(mongoUrl, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
  useFindAndModify: false
});

mongoose.connection.on('error', console.error.bind(console, 'connection error:'));
mongoose.connection.once('open', () => console.log("Successfully connected to MongoDB!"));

app.use(express.json());

require('./config/passport');
app.use(passport.initialize());

app.use(cors());

app.use('/api', apiRoutes);
app.use('/api/uploads', express.static('uploads'));

app.listen(port, () => console.log(`Server started on port ${port}.`));