-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const express=require("express"); | ||
const app=express(); | ||
const port=5000; | ||
const bodyParser = require('body-parser'); | ||
const mongoose=require("mongoose"); | ||
const usermodel= require("./models/usermodel"); | ||
mongoose.connect("mongodb://localhost:27017/mydatabase"); | ||
app.use(bodyParser.json()); | ||
app.use("/",(req,res)=>{ | ||
res.send("hello world"); | ||
}) | ||
app.post("/",(req,res)=>{ | ||
let name=req.name; | ||
let email=req.email; | ||
let password=req.password; | ||
console.log(`${name } ${email } ${password}`); | ||
usermodel.add({ | ||
name : name, | ||
email:email, | ||
password:password | ||
}) | ||
}) | ||
app.listen(port,()=>{ | ||
console.log(`server is running at port ${port}`); | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
const userSchema = mongoose.Schema({ | ||
name: { | ||
type: String, | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
}, | ||
password: { | ||
type: String, | ||
required: true | ||
} | ||
}); | ||
|
||
const userModel = mongoose.model("User", userSchema); | ||
|
||
const newUser = new userModel({ | ||
name: "Animesh sharma", | ||
email: "[email protected]", | ||
password: "123456678jj", | ||
}); | ||
|
||
newUser.save() | ||
.then(() => console.log("User added successfully")) | ||
.catch(err => console.error("Error adding user:", err)); | ||
|
||
module.exports = userModel; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.