1
+ const express = require ( 'express' )
2
+ const bcrypt = require ( 'bcryptjs' )
3
+ require ( './db/mongoose.js' )
4
+
5
+ const userRouter = require ( './routers/users' )
6
+ const taskRouter = require ( './routers/tasks' )
7
+
8
+ const app = express ( )
9
+
10
+
11
+ // {
12
+ // lastvisit:null
13
+ // util
14
+ // }
15
+
16
+
17
+ //Uploading Image to server
18
+ //========================================
19
+ // const multer = require('multer')
20
+ // const upload = multer({
21
+ // dest:'images',
22
+ // limits:{
23
+ // fileSize:1000000
24
+ // },
25
+ // fileFilter(req,file, cb){
26
+ // if(!file.originalname.match(/\.(doc|docx|jpg)$/)){
27
+ // return cb(new Error('Please Upload a word Document!'))
28
+ // }
29
+ // cb(undefined,true)
30
+ // // cb(new Error('File must be '))
31
+ // // cb(undefined,true)
32
+ // // cb(undefined,false)
33
+
34
+ // }
35
+ // })
36
+
37
+
38
+ // app.post('/upload',upload.single('uploadfile'),(req,res)=>{
39
+ // res.send()
40
+ // }, (error, req, res, next)=>{
41
+ // res.status(400).send({error: error.message})
42
+ // })
43
+ app . use ( express . json ( ) )
44
+ app . use ( userRouter )
45
+ app . use ( taskRouter )
46
+
47
+ //MASTER SWITCH To Enable and Disable services
48
+ //=================================================
49
+ // app.use((req,res,next)=>{
50
+
51
+ // // console.log(req.method, req.path)
52
+ // // next()
53
+ // if(envStatus === false ){
54
+
55
+ // res.status(503).send('POST/GET/PATCH/DELETE requests are disabled')
56
+
57
+ // }else{
58
+ // if(req.method === 'GET' || req.method === 'PATCH' || req.method ==='DELETE'){
59
+ // res.status(400).send('GET/PATCH/DELETE requests are disabled')
60
+ // }
61
+ // else{
62
+ // next()
63
+ // }
64
+ // }
65
+
66
+ // })
67
+
68
+ ///Adding file update to Express.!!!!
69
+ //=====================================================
70
+
71
+
72
+
73
+
74
+
75
+
76
+ //Password Encryption example using bcyrpt library
77
+ //=====================================================
78
+ // const myfunc=async ()=>{
79
+ // const pass='mypassword'
80
+ // const hashpass=await bcrypt.hash(pass,8)
81
+ // console.log(pass)
82
+ // console.log(hashpass)
83
+ // const isMatch = await bcrypt.compare('mypassword','$2a$08$9TxBexSjsy4QKiBj81rNLuqMuoUgzb/k/VgNvebgly66qH9NXJ1eG')
84
+ // console.log(isMatch)
85
+ // }
86
+
87
+ // myfunc()
88
+
89
+ //JWT Token example for generate Json Web token
90
+ //==================================================
91
+ // const jwt = require('jsonwebtoken')
92
+
93
+ // const myfunc = async()=>{
94
+ // const token = jwt.sign({_id:'abcd123'},'thisismynewcourse',{expiresIn:'7 seconds'})
95
+ // console.log(token)
96
+ // const data=jwt.verify(token,'thisismynewcourse')
97
+ // console.log(data)
98
+ // }
99
+ // myfunc()
100
+ // //Base64 Json string Base64 Encoded (payload/body) contains the id'abcd123' signature used to verify the token
101
+ // //part1{eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9}.part2{eyJfaWQiOiJhYmNkMTIzIiwiaWF0IjoxNTY1OTYwMzM3fQ}.part3{qh8LZF-AbfT7_AL9QR8kyve_E7bG5xqqwlwaNty6cd4}
102
+
103
+
104
+ // const pet = {
105
+ // name : 'Hal'
106
+ // }
107
+
108
+ // pet.toJSON = function(){
109
+ // console.log(this)
110
+ // return this
111
+ // }
112
+ // console.log(JSON.stringify(pet))
113
+
114
+ // const Task = require ('./models/tasks')
115
+ // const User = require('./models/users')
116
+
117
+ // const main = async ()=>{
118
+ // // const task = await Task.findById('5d598bcd788beb0e04a6fc36')
119
+ // // await task.populate('author').execPopulate()
120
+ // // console.log(task.author)
121
+ // const user = await User.findById('5d5af89e95437a20f0e07047')
122
+ // await user.populate('task').execPopulate()
123
+ // //console.log(user.task )
124
+
125
+ // }
126
+
127
+ // main()
128
+
129
+ // app.listen(port,()=>{
130
+ // console.log('App is running on Port: '+port)
131
+ // })
132
+
133
+ module . exports = app
0 commit comments