-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (25 loc) · 857 Bytes
/
index.js
File metadata and controls
34 lines (25 loc) · 857 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
27
28
29
30
31
32
33
import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import auth from './middleware/auth';
import userRoutes from './routes/userRoutes';
import surveyRoutes from './routes/surveyRoutes';
require('dotenv').config();
const app = express();
// Middleware land
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// DB Connection
mongoose.connect(process.env.DATABASE);
mongoose.Promise = global.Promise;
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
// Routing
app.use('/user', userRoutes);
app.use('/survey', surveyRoutes);
app.get('/auth', auth, (req, res) => {
res.status(200).json({ message: 'Auth ok' });
});
app.listen(process.env.PORT, () => {
console.log(`Listening on port ${process.env.PORT}`);
});