-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (31 loc) · 1.16 KB
/
server.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
const express = require('express');
const bodyParser = require('body-parser');
const notesController = require('./controllers/notes');
const authController = require('./controllers/auth');
const jwt = require('jsonwebtoken');
const expressjwt = require('express-jwt');
const ObjectID = require('mongoDB').ObjectID;
const db = require('./db');
const app = express();
const url = 'mongodb://localhost:27017';
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false}));
const jwtCheck = expressjwt({
secret: "mysupersecretkey"
});
app.get('/', (req, res) => {res.send('Hello API')});
app.get('/notes', notesController.all);
app.get('/notes/:id', jwtCheck, notesController.findById);
app.post('/notes', notesController.create);
app.post('/login', authController.login);
app.put('/notes/:id', notesController.update);
app.delete('/notes/:id', jwtCheck, notesController.delete);
app.delete('/notes/', notesController.deleteAll);
db.connect(url, (err) => {
if(err){
return console.log(err);
}
app.listen(3000, () => {
console.log('API app started');
});
});