const express = require("express"); //express import
const app = express();
const port = 5006;
const bodyParser = require("body-parser");
const { User } = require("./models/User");
//applicatioin /x-www-form -url encoded
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const mongoose = require("mongoose");
mongoose
.connect(
"mongodb+srv://euan:abcd1234@boilerplate.tywi2.mongodb.net/?retryWrites=true&w=majority",
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
}
)
.then(() => console.log("mongo db is connected.."))
.catch((err) => console.log(err));
app.get("/", (req, res) => {
res.send("Hello World122!");
});
app.post("/register", (req, res) => {
const user = new User(req.body);
user.save((err, userInfo) => {
if (err) return res.json({ success: false, err });
return res.status(200).json({
success: ture,
});
});
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});