-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (43 loc) · 1.79 KB
/
app.js
File metadata and controls
44 lines (43 loc) · 1.79 KB
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
43
44
/**************************************************************
* IT IS A SIMPLE TASK MANAGER API *
* WHERE USER CAN SIMPLY ADD TASKS *
* DELETES TASKS *
* UPDATE TASKS *
* GET ALL TASKS *
* GET SINGLE TASKS *
* USERS CAN REQUEST USING THE GIVEN ROUTES *
* app.get('api/v1/tasks') -get all tasks *
* app.post('api/v1/tasks') -post a task *
* app.get('api/v1/task/:id') -gets a single task *
* app.patch('api/v1/tasks/:id') -update a single task *
* app.delete('api/v1/tasks/:id') -deletes a single task *
* ************************************************************/
const express = require('express');
const connectDB = require('./db/connect')
const pageNotFound = require('./util/pageNotFound');
const errorHandler = require('./util/errorHandler');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3000;
//ENV
require('dotenv').config();
//routes
const tasks = require('./routes/tasks');
//middlewares
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.json());
//routes middleware
app.use('/api/v1/tasks', tasks);
//incase of incorrect request
app.use(pageNotFound)
//handles errors
app.use(errorHandler)
const start = async() => {
try {
await connectDB(process.env.MONGO_URL);
app.listen(PORT, () => console.log(`connected to port :${PORT}`))
} catch (err) {
console.log(`cannot connect :error ${err}`);
}
}
start()