Created
January 29, 2025 16:37
-
-
Save iamnabeelrahman/c07988b3afafd86e0877aeec5f061bbc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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