const express = require("express");
const app = express();
const port = 3000;
const mongoose = require("mongoose");
const User = require("./models/User");
mongoose.connect("mongodb+srv://huihyeon:1234@cluster0.beyce.mongodb.net/study?retryWrites=true&w=majority",{
useNewUrlParser:true,
useUnifiedTopology: true,
useCreateIndex:true,
useFindAndModify:false
}).then(()=>console.log("MongoDB connected..."))
.catch(err=>console.log(err));
app.use(express.urlencoded({extended: true}));
app.use(express.json());
app.get("/", (req,res)=> res.send("Hello World!"));
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:true
})
})
})
app.
listen(
port, ()
=> console.
log(
"server ON!") )