-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (32 loc) · 1.11 KB
/
index.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
require('dotenv').config();
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const { mongoURL } = require('./config/key');
const port = process.env.PORT || 3000;
const MONGO_URI = process.env.MONGO_URI || mongoURL;
app.set('views', './views');
app.set('view engine', 'ejs');
// for reading body json data
app.use(express.json());
// setting Public folder as static
app.use(express.static('./public'));
// connect to DB
mongoose
.connect(MONGO_URI, {
useCreateIndex: true,
useUnifiedTopology: true,
useNewUrlParser: true,
})
.then(() => console.log('MongoDB Connected....'))
.catch((err) => console.error(`Failed to connect: ${err}`));
// model register
require('./models/user');
require('./models/note');
// importing routes middleware
// app.use('/api/post', require('./routes/imgRoute'));
app.use('/api/user', require('./routes/authRoute'));
app.use('/api/note', require('./routes/crudRoute'));
app.use('/', require('./routes/defaultRoute'));
// Listening to the port
app.listen(port, () => console.log(`Server running on http://localhost:${port}....`));