0Pricing
WebSockets & Realtime Systems Programming · 강의

Node.js 프로젝트 설정

새 Node.js 프로젝트를 초기화하고 필요한 WebSocket 라이브러리(예: 'ws')를 설치합니다.

Node.js 프로젝트 설정은(는) CoddyKit의 무료 WebSockets & Realtime Systems Programming 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 WebSockets & Realtime Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. WebSockets & Realtime Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Welcome: Setting Up Node.js

Get ready to build your first WebSocket server! Our journey begins by setting up a new Node.js project. Node.js is a powerful JavaScript runtime that lets you run JavaScript code outside of a web browser.

This lesson will guide you through initializing your project and installing essential libraries.

Verify Node.js Installation

First things first, let's ensure Node.js and its package manager, npm (Node Package Manager), are installed on your system. Open your terminal or command prompt and run these commands:

node -v
npm -v

Initialize Your Project Folder

Every Node.js project typically lives in its own folder. Let's create one and then use npm init to set up the project. The -y flag answers all prompts with default values.

mkdir my-websocket-server
cd my-websocket-server
npm init -y

Understanding package.json

After running npm init -y, you'll find a new file named package.json in your project folder. This file is crucial! It acts as a manifest for your project, containing metadata and a list of all external libraries (dependencies) your project relies on.

{
  "name": "my-websocket-server",
  "version": "1.0.0",
  "description": "My first Node.js WebSocket server",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Installing the 'ws' Library

To build a WebSocket server, we need a special library to handle the WebSocket communication protocol. The ws library is a very popular, fast, and simple choice for Node.js.

Let's install it using npm:

npm install ws

Exploring node_modules

Once ws is installed, you'll see a new folder named node_modules appear in your project directory. This is where npm stores all the packages your project depends on, including ws and any of its own dependencies.

It can get quite large! You generally don't modify files inside node_modules directly.

Your First Node.js Script

Let's create a simple JavaScript file, index.js, to confirm our Node.js setup is working. In your project folder, create index.js and add this code:

// index.js
console.log("Hello CoddyKit from Node.js!");

Running Your Node.js Script

Now that you have your index.js file, you can run it directly using the node command in your terminal. Make sure you are in your project's root directory.

node index.js

Dependencies in package.json

After installing ws, if you open your package.json again, you'll notice a new "dependencies" section. This lists all the external packages your project needs to function, ensuring others can easily set up your project.

{
  "name": "my-websocket-server",
  "version": "1.0.0",
  "description": "My first Node.js WebSocket server",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ws": "^8.18.0" 
  }
}

Quick Check: Project Setup

You've learned the basics of setting up a Node.js project. Let's test your knowledge!

Recap & Next Steps

Fantastic work! You've successfully set up your first Node.js project for building a WebSocket server. Here's what we covered:

  • Verified Node.js and npm installations.
  • Initialized a new project with npm init.
  • Understood the role of package.json and node_modules.
  • Installed the ws library.
  • Ran a basic Node.js script.

Next, we'll dive into writing the actual server-side logic to handle WebSocket connections!

자주 묻는 질문

“Node.js 프로젝트 설정” 강의는 무료인가요?

네 — “Node.js 프로젝트 설정” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 WebSockets & Realtime Systems Programming 강의 전체를 잠금 해제할 수 있습니다. WebSockets & Realtime Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

“Node.js 프로젝트 설정”에서 뭘 배우나요?

새 Node.js 프로젝트를 초기화하고 필요한 WebSocket 라이브러리(예: 'ws')를 설치합니다. 브라우저에서 직접 실행하는 실습 코드로 WebSockets & Realtime Systems Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

WebSockets & Realtime Systems Programming을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 WebSockets & Realtime Systems Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“Node.js 프로젝트 설정” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 WebSockets & Realtime Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 WebSockets & Realtime Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. Node.js 프로젝트 설정
  2. 서버 측 로직 구현
  3. 클라이언트에 메시지 브로드캐스트
  4. 방과 채널 관리
← WebSockets & Realtime Systems Programming(으)로 돌아가기