Lee SeJin

mongodb schema update

...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
3 "version": "1.0.0", 3 "version": "1.0.0",
4 "description": "2021 OSS Project Using node!", 4 "description": "2021 OSS Project Using node!",
5 "scripts": { 5 "scripts": {
6 - "dev:server": "nodemon --exec babel-node src/server" 6 + "dev:server": "nodemon --exec babel-node src/init"
7 }, 7 },
8 "repository": { 8 "repository": {
9 "type": "git", 9 "type": "git",
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 "@babel/preset-env": "^7.14.1", 17 "@babel/preset-env": "^7.14.1",
18 "axios": "^0.21.1", 18 "axios": "^0.21.1",
19 "express": "^4.17.1", 19 "express": "^4.17.1",
20 + "mongoose": "^5.12.9",
20 "morgan": "^1.10.0", 21 "morgan": "^1.10.0",
21 "nodemon": "^2.0.7", 22 "nodemon": "^2.0.7",
22 "pug": "^3.0.2" 23 "pug": "^3.0.2"
......
1 import axios from "axios"; 1 import axios from "axios";
2 +import User from "../models/User";
2 3
3 const getQuote = async (req,res) =>{ 4 const getQuote = async (req,res) =>{
4 const url = "http://quotes.stormconsultancy.co.uk/random.json"; 5 const url = "http://quotes.stormconsultancy.co.uk/random.json";
......
1 +import mongoose from "mongoose";
2 +
3 +mongoose.connect("mongodb://127.0.0.1:27017/dev-profile",{
4 + useNewUrlParser: true,
5 + useFindAndModify: false,
6 + useUnifiedTopology: true
7 + }
8 +);
9 +
10 +const db = mongoose.connection;
11 +const handleOpen = () =>console.log("✅ Connected to DB");
12 +const handleError = (error) =>console.log(`❌ Error on DB Connection:${error}`);
13 +
14 +
15 +db.once("open", handleOpen);
16 +db.on("eror",handleError);
...\ No newline at end of file ...\ No newline at end of file
1 +import "./db";
2 +import "./models/User";
3 +import app from "./server";
4 +
5 +
6 +const PORT = 5500;
7 +const handleListening = () => console.log(`✅ Server running : http://localhost:${PORT}`);
8 +
9 +app.listen(PORT, handleListening);
...\ No newline at end of file ...\ No newline at end of file
1 +import mongoose from "mongoose";
2 +
3 +const UserSchema = new mongoose.Schema({
4 + name: {
5 + type: String,
6 + trim: true
7 + },
8 + email: {
9 + type: String,
10 + trim: true
11 + },
12 + avatarUrl: String,
13 + githubId: {
14 + type: Number,
15 + required: "GitHub id is required"
16 + },
17 + githubName: {
18 + type: String,
19 + required: "Github nickname is required",
20 + trim: true
21 + },
22 + school: {
23 + type: String,
24 + trim: true
25 + },
26 + tech: [{ type: String, trim: true }],
27 + career: [{ type: String, trim: true }],
28 + introduction: String,
29 + createdAt: {
30 + type: Date,
31 + default: Date.now
32 + },
33 + blogUrl: {
34 + type: String,
35 + default: "#"
36 + },
37 + githubUrl: {
38 + type: String,
39 + default: "#"
40 + }
41 +});
42 +
43 +const User = mongoose.model("User", UserSchema);
44 +
45 +
46 +export default User;
...\ No newline at end of file ...\ No newline at end of file
...@@ -5,7 +5,8 @@ import globalRouter from "./routers/globalRouter"; ...@@ -5,7 +5,8 @@ import globalRouter from "./routers/globalRouter";
5 import userRouter from "./routers/userRouter"; 5 import userRouter from "./routers/userRouter";
6 import { localsMiddleware } from "./middlewares"; 6 import { localsMiddleware } from "./middlewares";
7 7
8 -const PORT = 5500; 8 +
9 +
9 const app = express(); 10 const app = express();
10 11
11 12
...@@ -23,7 +24,6 @@ app.use("/users", userRouter); ...@@ -23,7 +24,6 @@ app.use("/users", userRouter);
23 24
24 25
25 26
26 -const handleListening = () => console.log(`✅ Server running : http://localhost:${PORT}`);
27 27
28 -app.listen(PORT, handleListening);
29 28
29 +export default app;
...\ No newline at end of file ...\ No newline at end of file
......