-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (29 loc) · 798 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
34
35
36
const express = require("express");
const app = express();
const port = 3000;
const config = require("./config/key");
const { User } = require("./models/User");
const mongoose = require("mongoose");
mongoose
.connect(config.mongoURI)
.then(() => console.log("MongoDB Connected..."))
.catch((err) => console.log(err));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.post("/register", (req, res) => {
const user = new User(req.body);
user.save((err, doc) => {
if (err)
return res.json({
success: false,
err,
});
return res.status(200).json({ success: true });
});
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});