forked from Afnan-Navaz/express-todo-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (28 loc) · 920 Bytes
/
index.js
File metadata and controls
32 lines (28 loc) · 920 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
/* eslint-disable max-len */
if (process.env.NODE_ENV != 'production') {
require('dotenv').config();
}
const express = require('express');
const mongoose = require('mongoose');
const path = require('path');
const app = express();
const user = require('./routes/user');
const todo = require('./routes/todo');
mongoose.connect(process.env.MONGO_URL, {useNewUrlParser: true, useUnifiedTopology: true})
.then(() => {
console.log('connected to mongodb');
})
.catch((err) => {
console.log(err);
});
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(express.json());
app.use(express.urlencoded({limit: '10mb', extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/api/user', user);
app.use('/api/todo', todo);
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`server up in port ${port}`);
});