관리 메뉴

ChangHoon's IT Blog

[Node.js] 실시간 채팅 서비스 1 - 준비단계 본문

Node.js

[Node.js] 실시간 채팅 서비스 1 - 준비단계

Hoonss 2019. 11. 6. 22:38

Node.js 를 사용하여 실시간 채팅 서비스를 구현해보려고 합니다.

 

Node.js 는 서버로

클라이언트는 으로 진행하겠습니다.

 

 


개발 환경 준비

https://nodejs.org/ko/download/

 

다운로드 | Node.js

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

nodejs.org

https://code.visualstudio.com/download

 

Download Visual Studio Code - Mac, Linux, Windows

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

code.visualstudio.com

위 링크를 통해 Node.js와 VSCode를 설치해 주세요

 

VSCode 를 설치한 뒤 원하는 폴더를 생성하고 VSCode 내부에서 터미널을 연 뒤 npm init를

진행하여 package.json 도 설치합니다.

 


필요한 모듈 설치

VSCode로 package.json 파일이 있는 폴더를 열어 줍니다.

 

그 후 터미널을 열어 줍니다.

이때 터미널은 Alt+T 를 누른뒤 새 터미널 열기를 눌러도 되고

Ctrl + ` 를 누르시면 열립니다.

 

터미널이 열리게 되면 커맨드 창에다가 아래 명령어를 입력해준다.

 

이때 주의할 점은 커맨드창에 표시된 경로는 본인이 폴더를 생성한 위치로 이동한 뒤 입력해야 한다.

 

npm install express --save

npm install socket.io --save

 

socket.io는 실시간 통신을 위한 모듈이며 express 는 Node.js에서 자주 사용되는 서버를 위한 모듈입니다.

 

그 후 package.json 파일을 열어보면

{
  "name": "nodechat",
  "version": "1.0.0",
  "description": "Node.js 실시간 채팅",
  "main": "index.js",
  "dependencies": {
    "express": "^4.17.1",
    "socket.io": "^2.3.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

dependencies 항목을 보면 express와 socket.io 가 있으면 성공적으로 한 것입니다.

(위의 구성은 개개인의 환경마다 차이가 있을 수 있습니다.)

 

여기까지 잘 따라오신 분들은 폴더안에

node-modules

package-lock.json

package.json

 

총 3개의 목록이 구성되어 있습니다.

 

감사합니다.

Comments