Lee SeJin

mongodb schema update

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