-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
27 lines (25 loc) · 848 Bytes
/
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
//imports
require('dotenv').config();
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const todoController = require('./controllers/todoController');
const PORT = process.env.PORT || 3200;
//routes api
app.use(express.json());
app.get('/todos', todoController.getAllTodo);
app.post('/todos', todoController.addTodo);
app.patch('/todos/:todoId', todoController.updateTodoById);
app.delete('/todos/:todoId', todoController.deleteTodoById);
app.get('/todos/:todoId', todoController.getTodoById);
//listener
app.listen(PORT, function(){
console.log('Server has started to run');
mongoose.connect(process.env.LOCAL_DB)
.then(function(){
console.log('DB is connected');
})
.catch(function(error){
console.log('Error connecting to Mongo DB', error.message);
})
});