-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongotest.js
More file actions
39 lines (31 loc) · 870 Bytes
/
mongotest.js
File metadata and controls
39 lines (31 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const express = require("express");
const jwt = require("jsonwebtoken");
const mongoose = require("mongoose");
const jwtPassword = "123456";
const app = express();
app.use(express.json());
mongoose.connect(
"mongodb+srv://admin:12345@cluster0.eghvz.mongodb.net/user_app",
);
const User = mongoose.model('Users', {name: String, email: String, password: String})
app.post("/signup", async (req, res) => {
const username = req.body.username;
const password = req.body.password;
const name = req.body.name;
const user = new User({
name: name,
email: username,
password: password
});
const existUser = await User.findOne({email: username});
if(existUser) {
return res.status(400).json({
msg: "username already exists."
})
}
user.save();
return res.json({
msg: "user created successfully"
});
})
app.listen(3000);