-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
81 lines (49 loc) · 1.19 KB
/
app.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const express = require('express')
const morgan = require('morgan')
const mongoose = require('mongoose')
const router = require('./routes')
const app = express()
app.use(morgan('dev'))
app.use(express.urlencoded({ extended: true}))
app.use(express.json())
/*
let Schema = mongoose.Schema
let testSchema = new Schema({
name: String
})
//create model
//name of the model is Test
let Test = mongoose.model('Test',testSchema)
*/
app.use('/Contact', router)
app.get('/', (request,response) => {
/*
//crete a object
let test = new Test({
name: 'Asiful Bijoy'
})
test.save()
.then(t=>{
response.json(t)
})
.catch(e=>{
console.log(e)
//server error is 500 so that we use 500
response.status(500).json({
error: 'error occurred'
})
})
*/
})
const PORT= process.env.PORT || 8080
mongoose.connect(`mongodb+srv://ab101:ab101@cluster0.wi1os.mongodb.net/test`,{
useNewUrlParser: true
}) // function call will return a promise
.then(()=>{
app.listen(PORT,()=>{
console.log(`server is running on PORT ${PORT}`)
})
})
.catch(e=>{
console.log(e)
})