-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (23 loc) · 942 Bytes
/
server.js
File metadata and controls
31 lines (23 loc) · 942 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
import express from 'express';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import { config } from 'config/config';
const userController = require('@/api/users/userController');
const profileController = require('@/api/profiles/profileController');
const postController = require('@/api/posts/postController');
const app = express();
// Body parser middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Connect to MongoDB
mongoose
.connect(config.db.uri, { useNewUrlParser: true })
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log(err));
app.get('/', (req, res) => res.send('Hello'));
// Use routes
app.use('/api/users', userController);
app.use('/api/profiles', profileController);
app.use('/api/posts', postController);
const port = process.env.port || 5000;
app.listen(port, () => console.log(`Server running on port ${port}`));