게시판 로직 - Post, postController, postRoutes
| Post 모델 스키마 정의 backend/models/Post.js// backend/models/Post.jsconst mongoose = require('mongoose');const postSchema = new mongoose.Schema({ title: { type: String, required: true, }, content: { type: String, required: true, }, author: { type: mongoose.Schema.Types.ObjectId, // 유저 참조 ref: 'User', required: true, }}, { timestamps: true }); // createdAt, updatedAt 자동 생성m..
2025. 4. 30.
NodeJS, MongoDB, react 회원가입, 로그인, 게시판 구현 플로우
Node.js / MongoDB / React를 활용한 프로젝트를 만들어 보려 한다.회원가입을 하고 로그인을 하면 게시판 글쓰기가 가능한 기본적인 기능을 시작으로 점진적으로 기능을 추가해 볼 예정이다. 1. 프로젝트 폴더 및 구조 구성 2. backend, frontend 구성 및 설치 3. backend 1) 서버 시작 파일 작성 및 환경변수 파일 작성 ( server.js, .env ), nodemon설정 2) MongoDB 연결 및 서버 실행 ( db.js, errorHandler.js )3) 회원가입, 로그인 로직 작성 ( User.js, authController.js, authRoutes.js, generateToken.js )4) 게시글 로직 작성 ( Post.js, postControll..
2025. 4. 30.
회원가입, 로그인 로직 - User, authController, authRoutes
| User 모델 스키마 정의데이터 스키마를 정의하고 DB와 연결된 구조를 제공한다. backend/models/User.jsconst mongoose = require('mongoose');const bcrypt = require('bcryptjs');const userSchema = new mongoose.Schema({ username: { type: String, required: true, unique: true }, email: { type: String, required: true, unique: true }, password: { type: String, required: true }}, { timestamps: true });userSchema.pre('save', async fu..
2025. 4. 30.