-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (33 loc) · 1.06 KB
/
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
37
38
39
40
41
42
const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
const app = express();
const logger = require('./middlewares/logger');
//connect with mongoose
async function asdf() {
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', async () => {
// we're connected!
console.log('connected');
});
await mongoose.connect('mongodb://localhost:27017/exampleapp', {
authSource: 'admin',
user: 'admin',
pass: 'admin',
useNewUrlParser: true,
useUnifiedTopology: true
});
}
asdf();
//innit middleware
app.use(logger);
//Body Parser Middleware
app.use(express.json());
app.use(express.urlencoded({ extended:false }));
//setting static folder
app.use(express.static(path.join(__dirname, 'public')));
//Members Api Routes
app.use('/api/members', require('./routes/api/allMembers'));
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server starting on port: ${PORT}...`));