-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3fb6cb
commit 3fe13ad
Showing
7 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PORT=5000 | ||
MONGO_URI=mongodb+srv://techxcel:[email protected]/?retryWrites=true&w=majority |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import mongoose from "mongoose"; | ||
|
||
export const connectDB = async (uri) => { | ||
await mongoose.connect(uri); | ||
console.log("connected to MongoDB!"); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import mongoose from "mongoose"; | ||
import validator from "validator"; | ||
|
||
const userSchema = new mongoose.Schema({ | ||
name: { | ||
type: String, | ||
required: [true, "Please enter your name"], | ||
}, | ||
email: { | ||
type: String, | ||
unique: true, | ||
required: [true, "Please enter your email"], | ||
validate: { | ||
validator: validator.isEmail, | ||
message: "Please enter a valid email", | ||
}, | ||
}, | ||
password: { | ||
type: String, | ||
required: [true, "Please enter your password"], | ||
}, | ||
role: { | ||
type: String, | ||
enum: ["admin", "student", "faculty"], | ||
required: true, | ||
}, | ||
profilePicture: { | ||
type: String, | ||
validate: { | ||
validator: validator.isURL, | ||
message: "Invalid URL", | ||
}, | ||
}, | ||
createdAt: { | ||
type: Date, | ||
default: Date.now, | ||
}, | ||
}); | ||
|
||
export default mongoose.model("User", userSchema); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import express from "express"; | ||
import cors from "cors"; | ||
import dotenv from "dotenv"; | ||
import { connectDB } from "./db/connectDB.js"; | ||
|
||
dotenv.config(); | ||
const app = express(); | ||
const port = process.env.PORT || 5000; | ||
app.use(cors()); | ||
app.use(express.json()); | ||
|
||
const start = async () => { | ||
try { | ||
await connectDB(process.env.MONGO_URI); | ||
app.listen(port, () => { | ||
console.log(`Server is listening on port ${port}`); | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
start(); |