프로그래밍/Node.js

[14] 회원가입, 로그인, 게시판CRUD 구현해보자! (Node.js x mySQL x sequelize) 1탄

제이스톨 2023. 7. 13. 21:08
728x90

1. 들어가기 전에

개발자라고 하면 모두들 CRUD는 기본이라고한다. 하지만 이 CRUD를 구현한다는게 가장 어렵고 이를 자유자재로 구현하게 되면 그때서야 비로소 초급 개발자의 문턱에 들어갔다고 생각한다.

지금부터 node.js 환경세팅부터 회원가입, 로그인, 게시판CRUD기능 구현, 댓글, 좋아요 기능까지 순차적으로 알아보는 시간을 가져보겠다.

 

※ 파일구조

프로젝트 폴더 이름
├── app.js
│    └──assets(frontEnd)
│    │   └── index.html
│    └──config
│    │   └── config.json
│    └── middleware
│    └── migration
│    │   └── create-users.js
│    │   └── create-posts.js
│    │   └── create-cmt.js
│    ├── model
│    │   ├── index.ts
│    │   └── users.js
│    │   └── posts.js
│    │   └── cmt.js
│    └── route
│        └── usersRoute.js
│        └── postsRoute.js
│        └── cmtRoute.js
└── package.json
└── package-lock.json

2. node.js 환경세팅 (with mySQL)

https://jh-healing-place.tistory.com/90

위에 게시물에서 한번 정리를 한적이 있었는데 제대로 정리가 안된거같아서 한번 더 차근차근 정리하고자한다.

 

2-1. node.js + mySQL 환경세팅

# 1. 가장 먼저 개발 tool을 설치해준다.

https://code.visualstudio.com/

 

Visual Studio Code - Code Editing. Redefined

Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.  Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.

code.visualstudio.com

 

# 2. node.js와 mySQL을 버전 확인 후 설치해준다.

https://nodejs.org/ko/download

 

다운로드 | Node.js

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.

nodejs.org

https://www.mysql.com/downloads/

 

MySQL :: MySQL Downloads

MySQL Cluster CGE MySQL Cluster is a real-time open source transactional database designed for fast, always-on access to data under high throughput conditions. MySQL Cluster MySQL Cluster Manager Plus, everything in MySQL Enterprise Edition Learn More » C

www.mysql.com

 

# 3. vscode 내에서 thunderClient라는 api 확인용 플러그인과 mySQL플러그인을 설치해준다. ( 이건 본인이 사용하는 tool을 사용하면 될거같아요)

mySQL
thunderClient

 

# 4. 이렇게 설치가 완료되었으면 빈 폴더 하나를 만들어준다.

 

#5. 빈 폴더를 vscode에서 실행시켜주고 app.js라는 파일 하나를 만들어준다.

// app.js

const express = require('express');
const app = express();
const port = 3000;

const path = require('path');

// HTML, CSS
app.use(express.static(path.join(__dirname, 'assets')));
app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, 'assets', 'index.html'));
});

app.listen(port, () => {
  console.log(port, '포트가 열렸습니다~^^');
});

 

# 6. app.js 파일에 대한 터미널 창을 열고 npm init을 쳐준다. ( 이러면 package.json 폴더가 생성될 것이다 )

 

# 7. npm i express

 

# 8. npm install express sequelize mysql2

 

# 9. npm install -D sequelize-cli

 

# 10. npx sequelize init

 

# 11. 위 과정을 모두 마친 후 터미널에 node app.js를 치면 localhost:3000 서버가 실행될 것이다.

정상적으로 서버가 켜진 모습

 


이렇게 하면 CRUD작업을 위한 환경세팅은 다 끝났다.

2탄에서는 본격적으로 로그인, 로그아웃 기능을 구현하고

게시판 CRUD 기능을 만들어보겠다!

 

1탄 끝~~

2탄 링크 바로가기 ▼

https://jh-healing-place.tistory.com/117

 

[15] 회원가입, 로그인, 게시판CRUD 구현해보자! (Node.js x mySQL x sequelize) 2탄

1. 들어가기 전에.. 여기서는 본격적으로 로그인, 로그아웃 기능을 위해 user라는 DB를 만들고 게시글과 댓글 기능을 위한 post와 cmt라는 DB를 만들어보도록 하겠다. ( 환경세팅 방법은 아래 1탄에 있

jh-healing-place.tistory.com

 

728x90