-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (56 loc) · 4.02 KB
/
index.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
const express = require('express');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
const app = express();
app.use(express.json());
dotenv.config();
const PORT = process.env.PORT || 5001;
/////// DEFAULT ROUTE FOR DESSCIPTION
app.get('/', (req, res) => {
const htmlResponse = `
<html>
<head><title>EFFIONG GODSWILL : HNG10 </title></head>
<body>
<h2>TASK TWO :</h2>
<h3>NAME: EFFIONG GODSWILL O.</h3>
<p>Slack Name: wilz</p>
<p>Track:</p>
<p>Github File URL: <a href="https://github.com/DONNWILZY/HNGTaskTwo/blob/master/index.js" target="_blank">/// https://github.com/DONNWILZY/HNGTaskTwo/blob/master/index.js</a></p>
<p>Github Repo URL: <a href="https://github.com/DONNWILZY/HNGTaskTwo" target="_blank">/// https://github.com/DONNWILZY/HNGTaskTwo</a></p>
<p></p>
<h2> END POINTS</h2>
<P> <b>CREATE USER:</b> <a href="https://hngtasktwo.vercel.app/api" target="_blank">https://hngtasktwo.vercel.app/api</a></p> </P>
<P> <b>UPDATE USER BY ID:</b> <a href="https://hngtasktwo.vercel.app/:user_id" target="_blank">https://hngtasktwo.vercel.app/:user_id</a></p> </P>
<P> <b>GET USER BY ID:</b> <a href="https://hngtasktwo.vercel.app/:user_id" target="_blank">https://hngtasktwo.vercel.app/:user_id</a></p> </P>
<P> <b>DELETE USER BY ID :</b> <a href="https://hngtasktwo.vercel.app/api/:user_id" target="_blank">https://hngtasktwo.vercel.app/api/:user_id"</a></p> </P>
<P> <b>GET ALL USERS:</b> <a href="https://hngtasktwo.vercel.app/api" target="_blank">https://hngtasktwo.vercel.app/api</a></p> </P>
<P> <b>UML DIAGRAM</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4o3vsA1sYZd6JoH4mDbkU%2BwUJEyJQ5WW9HrEvD6Ht7z2IVIGHUnjTORMKwXNncHkLiW4YZYLa9pOFwjOiu1f5bawzWfse1sTvzK2RNuJT7i1HCQJV3qtMmSVkPAPJMlU5WriXS9WZbEjWhDJf8YGJRjC4veJgxafSGXzoRBqy9aesOF5eorCbOcbGblTlpNpA963t0VlG3v9IpymA2jXTbM2qIjn8mGrVYSmbbZKBvm1RedfesMJ6ORlebo4mK2CpBaA8g8EyC9vmTpDQN0xJ8jlwPU3EblaHysVvHRavhY5%2BKjV%2BuPrdpXwod1d%2F%2FbZcN3f4uqzl8%3D">UML DIAGRAM</a></p> </P>
<P> <b>README.MD</b> <a href="https://github.com/DONNWILZY/HNGTaskTwo/blob/master/README.md">https://github.com/DONNWILZY/hngTaskOne/blob/master/README.md</a></p> </P>
</body>
</html>
`;
res.send(htmlResponse);
});
const userRoute = require('./route/userRoute');
app.use('/api', userRoute);
// Database connection
mongoose.connect(process.env.databaseUrl, { useNewUrlParser: true, useUnifiedTopology: true });
const db = mongoose.connection;
/// db connection error
db.on('error', (error) => {
console.error('Connection error:', error);
});
//// db connecrion status.Successful message
db.once('open', () => {
console.log('Connection to MongoDB successful!');
});
//// db connecrion status.failure message
db.once('close', () => {
console.log('Connection to MongoDB disconnected.');
});
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});
app.on('disconnect', () => {
console.log('disconnected');
});