Eric Whale

Add mongoDB and it's config

1 const jwt = require("jsonwebtoken"); 1 const jwt = require("jsonwebtoken");
2 const bcrypt = require("bcryptjs"); 2 const bcrypt = require("bcryptjs");
3 +// handles "exception" inside of async express routes
4 +// (Used for mongoDB error in this project)
3 const asyncHandler = require("express-async-handler"); 5 const asyncHandler = require("express-async-handler");
4 6
5 // @desc Signup new user 7 // @desc Signup new user
...@@ -29,7 +31,10 @@ const loginUser = asyncHandler(async (req, res) => { ...@@ -29,7 +31,10 @@ const loginUser = asyncHandler(async (req, res) => {
29 // Send response 31 // Send response
30 }); 32 });
31 33
34 +const getSelf = asyncHandler(async (req, res) => {});
35 +
32 module.exports = { 36 module.exports = {
33 signupUser, 37 signupUser,
34 loginUser, 38 loginUser,
39 + getSelf,
35 }; 40 };
......
1 -const colors = require("colors");
2 const mongoose = require("mongoose"); 1 const mongoose = require("mongoose");
2 +const colors = require("colors");
3 3
4 -const connectDB = async () => {}; 4 +const connectDB = async () => {
5 + try {
6 + const conn = await mongoose.connect(process.env.MONGO_URI);
7 + console.log(`MongoDB Connected: ${conn.connection.host}`.cyan.underline);
8 + } catch (error) {
9 + console.log(error);
10 + process.exit(1);
11 + }
12 +};
5 13
6 module.exports = connectDB; 14 module.exports = connectDB;
......
1 +const mongoose = require("mongoose");
2 +
3 +const userSchema = mongoose.Schema(
4 + {
5 + username: {
6 + type: String,
7 + required: [true, "Please add a username"],
8 + },
9 + email: {
10 + type: String,
11 + required: [true, "Please add a email"],
12 + },
13 + password: {
14 + type: String,
15 + required: [true, "Please add a password"],
16 + },
17 + },
18 + {
19 + timestamps: true,
20 + }
21 +);
22 +
23 +const userModel = mongoose.model("User", userSchema);
24 +module.exports = userModel;