-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (29 loc) · 897 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
const mongoose = require("mongoose");
const express = require("express");
const bodyParser = require("body-parser");
const Submission = require("./Submission");
const cors = require('cors');
require('dotenv').config();
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const mongoUrl = 'mongodb+srv://shreyaslshah:[email protected]/exodus22?retryWrites=true&w=majority'
mongoose.connect(
mongoUrl,
{ useNewUrlParser: true }
);
app.post('/submit', async function(req,res){
const details = req.body.details;
const link = req.body.link;
try {
const doc = await Submission.create({details, link});
res.status(200).send(doc);
} catch (error) {
console.log(error);
throw new Error('could not submit');
}
})
app.listen(3010, () => {
console.log("Server runnig on port 3010");
})