-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (27 loc) · 901 Bytes
/
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
const express = require('express');
const cors = require('cors');
const app = express();
const bodyParser = require('body-parser')
const User = require('./schemas/User')
const mongoose = require('mongoose')
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.json());
app.get('/get', (req,res,next) => {
User.find({},'email', function(err,results) {
if (err || !results) res.send({ success: false})
res.send({ success: true, results: results })
})
});
app.post('/post', (req,res, next) => {
var newUser = new User(req.body);
newUser.createUser(req,res,next);
})
app.listen(4000, () => mongoose.connect('mongodb://localhost/test'));