본문 바로가기

전체 글

(132)
Node.js(18) - MySQL 제약조건, Foreign Key 추가 방법, JOIN, sequelize를 활용한 코드 구현 1) Node.js 1-1) MySQL 제약조건 1-2) Foreign Key(외래키) 추가 방법 1-3) JOIN 1-4) sequelize를 활용한 코드 구현 1) Node.js 1-1) MySQL 제약조건 기본적으로 제약조건은 세가지가 있는데 "기본키", "고유키", "외래키"이다!! (1) 기본키(Primary Key) 중복되지 않는 고유값 Null을 허용하지 않음 테이블 당 하나의 기본키만 지정 가능함 (2) 고유키(Unique) 중복되지 않는 고유값 Null을 허용함 (3) 외래키(Foreign Key) 자식 테이블에게 field 하나를 추가하는데 이때 추가하는 field는 부모 테이블의 고유한 식별자(Foreign Key)를 추가하면 됨 1:1 --> User 테이블의 데이터 중 회원들로부터..
Node.js(17) - 모델 생성 방법(User: define 함수 / Comment: class 활용), sequelize를 활용한 CRUD 구현 1) Node.js 1-1) 모델 생성 방법 - User(define 함수 활용), Comment(class 활용) 1-2) sequelize를 활용한 CRUD 구현 1) Node.js 1-1) 모델 생성 방법 - User(define 함수 활용), Comment(class 활용) Sequelize express 기본세팅을 먼저 한 뒤 Sequelize 기본세팅을 진행함! $ npm init -y $ npm install express cors mysql2 sequelize dotenv server.js const express = require("express"); const app = express(); app.listen(3000, () => { console.log(`server start`); ..
Node.js(16) - Backend 구현(dotenv, config, 예외처리) 및 User Table 추가(ORM 적용: sequelize 활용) 1) Node.js 1-1) Back-end 구현(dotenv, config, 예외처리) 1-2) Back-end User Table 추가(ORM 적용: sequelize) 1) Node.js 1-1) Back-end 구현(dotenv, config, 예외처리) | GET /comments | GET /comments/:id | POST /comments | PUT /comments/:id | DELETE /comments/:id dotenv(.env) 라이브러리: 시스템 환경변수를 ".env 파일"을 읽어서 적용시키는 것을 의미함! 참고로 ".env 파일" 상의 "NODE_ENV=development"는 개발모드를 의미한다!! Router --> Controller --> Service --> Repo..
Node.js(15) - Backend MVC 패턴 구현, class(상속 및 추상화)를 활용한 댓글 Front 화면 구현 1) Node.js 1-1) Back-end MVC 패턴 구현 1-2) 댓글 front 화면 구현 - class 활용(상속 및 추상화) 1) Node.js 1-1) Back-end MVC 패턴 구현 back server.js const express = require("express"); const app = express(); const cors = require("cors"); const router = require("./routes/comment.route"); app.use(express.urlencoded({ extended: false })); app.use(express.json()); app.use( cors({ origin: true, credentials: true, }) ); app..
Node.js(14) - back 댓글 CRUD 구현, 모듈 및 class를 활용한 댓글 front 화면 구현 1) Node.js 1-1) 댓글 CRUD 구현 - back 1-2) 댓글 front 화면 구현(CRUD) - 모듈 및 class 활용 1) Node.js 1-1) 댓글 CRUD 구현 - back back server.js const express = require("express"); const cors = require("cors"); const app = express(); const mysql = require("./models"); app.use(express.urlencoded({ extended: false })); app.use(express.json()); app.use( cors({ origin: true, credentials: true, }) ); /* `id` `userid` `c..
Node.js(13) - XMLHttpRequest/fetch/axios, 비동기 통신 댓글 CRUD(axios 활용) 1) Node.js 1-1) XMLHttpRequest, fetch, axios 1-2) 비동기 통신 - 댓글 CR(Create, Read) 1-3) 비동기 통신 - 댓글 UD(Update, Delete) 1) Node.js "요청을 잘 보내고 잘 받는 것"에 숙달되는 것이 중요하다!! "display: none;"된 element가 "template element"이다!! 어떤 요청을 보내면 어떻게 응답을 줄지(구체적으로 어떤 데이터 타입으로 줄지를 명시한 것을 의미함)를 정의한 것이 "API 문서"이다!! 1-1) XMLHttpRequest, fetch, axios const request = ({ method, path, body }) => { return new Promise((resolve, r..
Node.js(12) - 비동기 통신 댓글 CRUD, Postman 및 Database 활용 1) Node.js 1-1) 비동기 통신 - 댓글 CRUD(Postman 활용) 1-2) Database 활용 1) Node.js 1-1) 비동기 통신 - 댓글 CRUD(Postman 활용) 비동기 통신(callback or Promise or async/await) 초기 세팅 : front(3005번 port)와 back(3000번 port) 디렉토리를 만들고 front, back 디렉토리 각각 터미널을 키고 시작 XMLHttpRequest --> fetch --> axios → 위의 내용들이 잘 숙달되면 back-end를 잘 만드는 스킬들을 배울 예정! 기존 게시판 CRUD GET /board/list POST /board/write GET /board/view POST /board/modify?id..
Node.js(11) - AJAX 기본 포맷, server 분리(front/back) 구현 1) Node.js 1-1) 비동기 통신의 기본 로직(AJAX 기본 포맷) 1-2) server 분리(front, back) 후 AJAX 구현 1) Node.js 1-1) 비동기 통신의 기본 로직(AJAX 기본 포맷) GET / index.html GET /ajax GET POST /ajax POST $ npm init -y $ npm install express ※ 브라우저가 "Content-Type"에 따라 읽는 모드가 달라진다! --> 이로 인해 "Content-Type"이 달라지면 요청을 새로 다시 보낸다!! ※ url을 안바꾸고 요청을 만들어서 보내는 것이 "AJAX"의 기본원리이다!! server.js const express = require("express"); const nunjucks ..