Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save iamnabeelrahman/c07988b3afafd86e0877aeec5f061bbc to your computer and use it in GitHub Desktop.

Select an option

Save iamnabeelrahman/c07988b3afafd86e0877aeec5f061bbc to your computer and use it in GitHub Desktop.
const express = require("express")
const mongoose = require("mongoose")
const app = express()
mongoose.connect(`{oaiehflzkct/backendsession`)
.then(() => console.log("Mongodb Conected"))
.catch((error) => console.log("failed to connect Mngodb"));
const userSchema = new mongoose.Schema({
gender: String,
fullName: String,
email: String,
password: String
}, {timestamps: true})
const User = mongoose.model("User", userSchema)
app.use(express.json())
// body, query, params,headers, cookies
app.post("/", async (req, res) => {
const { gender, fullName, email, password} = (req.body)
const newUser = await User.create({
gender,
fullName,
email,
password
})
if (newUser) {
return res.status(200).json({
success: true,
message: "User created Successfully!",
user: newUser
})
}
res.json({
msg: "error creating user"
})
})
app.listen(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment