-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
54 lines (43 loc) · 1.12 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
const express = require("express")
const app = express()
const bcrypt = require("bcrypt")
const mongoose = require("mongoose")
const router = require('./routes/userRoutes')
const dotenv = require("dotenv");
dotenv.config();
const users = []
const port = process.env.PORT || 5000;
app.use(express.json());
// app.use(express.urlencoded({ extended: false }))
app.use('/api/users',router);
app.get("/service", async (req, res) => {
res.render("service.ejs")
})
app.get('/', (req, res) => {
res.render("index.ejs")
})
app.get('/login', (req, res) => {
res.render("login.ejs")
})
app.get('/register', (req, res) => {
res.render("register.ejs")
})
app.get('/user', (req, res) => {
res.render('user.ejs')
})
app.get('*', (req,res) => {
res.send("404 not found");
})
const start = async () => {
try {
mongoose.set('strictQuery',false);
await mongoose.connect(process.env.MONGO_URI);
console.log(`connected to database..`);
app.listen((port), () => {
console.log(`app is listening on port ${port}`);
})
}catch(err){
console.log(err);
}
}
start();