-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (36 loc) · 1.09 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
36
37
38
39
40
41
42
43
const express = require('express'),
app = express(),
port = process.env.PORT || 3500,
mongoose = require('mongoose'),
habeeb = require('./Habeeb');
bodyParser = require('body-parser');
// mongoose instance connection url connection
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/Tododb', { useNewUrlParser: true })
.then( (db)=>{
console.log('db connected');
}).catch( (error)=>{
console.log('db error occured', error);
});
habeeb.checkName('Makinde').then( (response)=>{
console.log(response);
}).catch( (error)=>{
console.log(error);
});
const isAgeValid = habeeb.checkAge(1);
if(isAgeValid){
console.log('yeah it is valid');
}
else{
console.log('nay! it is not valid');
}
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const routes = require('./api/routes/todoListRoutes'); //importing route
routes(app); //register the route
app.use(function(req, res) {
res.status(404).send({url: req.originalUrl + ' not found'})
});
app.listen(port, ()=>{
console.log('todo list RESTful API server started on: ' + port);
});