forked from Elpugna/Node-Express-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
66 lines (52 loc) · 1.91 KB
/
Copy pathapp.js
File metadata and controls
66 lines (52 loc) · 1.91 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const express = require("express");
const app = express();
const tasks = require('./routes/tasks');
//Database and environment stuff
const connectDB = require('./db/connect');
require('dotenv').config();
const notFound = require('./middleware/not-found');
const errorHandler = require("./middleware/error-handler");
//middleware
app.use(express.static('./public'));
app.use(express.json());
//routes
app.use('/api/v1/tasks', tasks)
app.use(notFound);
app.use(errorHandler);
//App Methods:
//app.get('/api/v1/tasks') - Get all the tasks
//app.post('/api/v1/tasks') - Create a new task
//app.get('/api/v1/tasks/:id') - Get single task
//app.patch('/api/v1/tasks:id') - Update task
//app.delete('/api/v1/tasks:id') - delete task
//we use "PORT=number node app.js" and the app will run un that port. If not, the app will run om port 3000.
const port =process.env.PORT || 3000;
//conecting the DB before the server starts listening
const start =async ()=>{
try{
await connectDB(process.env.MONGO_URI)
app.listen(port, ()=>{
console.log(`Server listening on port ${port}`)
})
}catch(err){
console.log(err);
}
}
start();
/*
REST API:
-REpresentational State Transfer. It is a design pattern. It combines HTTP verbs, route paths, and resourses(data).
-Our approach:
--We have our main list of orders (we order tasks in this case with our HTTP methods).
--We use JSON to send and recieve data.
--We allow the user to perform CRUD(create, read, update ,delete) data from our database.
MONGODB:
-NoSQ, Non relational DB:
It don't care how the data relates to each other.
--We have collections (groups of items) instead of columns
--we have documents instead of rows that represent a single items. It is a set of key/value data pair that can have multiple kind of data (numbers, strings, objects, etc)
-Store JSON:
-Easy to get started:
-Free Cloud Hosting -Atlas:
*/
//2:11:46