-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
38 lines (32 loc) · 852 Bytes
/
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
const mongoose = require('mongoose');
const express = require('express');
const app = express();
const detailSchema = mongoose.Schema({
name: {
type: String,
required: true,
},
phone: {
type: Number,
required: true,
unique: true,
},
});
const cust_details = mongoose.model('cust_details', detailSchema);
app.use(express.json());
//serves static files
app.use(express.static(`${__dirname}/public`));
app.get('/contacts', (req, res) => {
cust_details
.create(req.query)
.then(() => {
// res.send(`<i> thank you we will update you with hostel details <i>
// <a href="/">go back<a>`);
res.status(204).send();
})
.catch((err) => {
res.send(`<i> Something went wrong try again <i>
<a href="/">try again<a><br> Name/Number already exists!!`);
});
});
module.exports = app;