-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (41 loc) · 1.4 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
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const MongoClient = require('mongodb').MongoClient
const session = require('express-session');
const passport = require('passport');
const server = express();
server.use(bodyParser.json());
server.use(express.static('public'));
var path = require('path');
server.use(bodyParser.urlencoded({ extended: true }));
const User = require("./models/userModel");
var usercollection = '';
const db = encodeURI("mongodb+srv://d8paul:[email protected]/test?retryWrites=true&w=majority");
const client = new MongoClient(db, { useUnifiedTopology: true,useNewUrlParser: true});
client.connect(err => {
usercollection = client.db("users").collection("appusers");
console.log('Connected to Database');
// perform actions on the collection object
//client.close();
});
server.get('/', function(req, res) {
res.sendFile(path.join(__dirname, '/public/views', 'index.html'));
});
server.post('/patient/signup',
[ ], (req, res) => {
usercollection.insertOne(req.body)
.then(result => {
return result.status(200).json({
msg: 'user was saved'
});
})
.catch(error => {
console.log('error while saving');
});
}
);
// Listener
server.listen(3000, function() {
console.log('listening on Port: 3000')
});