Node.js

 

Node.js를 5주 동안 학습하는 커리큘럼을 구성했습니다. 이 커리큘럼은 주차별로 학습 목표와 주요 학습 내용을 포함하며, 실습 예제를 통해 학습을 강화합니다.

 

1주차: Node.js 기본 개념 및 환경 설정

목표

  • Node.js와 npm(Node Package Manager)의 설치 및 환경 설정
  • Node.js의 기본 개념과 특징 이해
  • 간단한 Node.js 애플리케이션 작성

학습 내용

  • Node.js 설치 및 설정
    • Node.js와 npm 설치
    • 설치 확인 (node -v, npm -v)
    • Node.js REPL (Read-Eval-Print Loop) 사용해보기
  • Node.js 기본 개념
    • Node.js의 이벤트 기반 비동기 I/O 모델 이해
    • Node.js의 장점과 특징
    • 기본 모듈 시스템 (CommonJS)
  • 첫 번째 Node.js 애플리케이션
    • 간단한 "Hello, World!" 서버 작성
const http = require('http');

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, World!\n');
});

server.listen(3000, '127.0.0.1', () => {
  console.log('Server running at http://127.0.0.1:3000/');
});

 

2주차: Node.js 모듈 시스템과 파일 시스템

목표

  • Node.js의 모듈 시스템 이해
  • 파일 시스템 모듈 사용법 익히기
  • 비동기 파일 읽기/쓰기 작업 수행

학습 내용

  • Node.js 모듈 시스템
    • 모듈 정의 및 사용 (exports, require)
    • 내장 모듈 사용 (예: path, os)
    • 사용자 정의 모듈 작성 및 사용
  • 파일 시스템 (fs) 모듈
    • 동기 및 비동기 파일 읽기/쓰기
    • 파일 시스템 조작 (파일 삭제, 디렉터리 생성 등)
const fs = require('fs');

// 비동기 파일 읽기
fs.readFile('example.txt', 'utf8', (err, data) => {
  if (err) throw err;
  console.log(data);
});

// 비동기 파일 쓰기
fs.writeFile('example.txt', 'Hello, Node.js!', (err) => {
  if (err) throw err;
  console.log('File has been saved!');
});

 

3주차: HTTP 모듈과 Express.js 기본

목표

  • HTTP 모듈을 사용한 간단한 웹 서버 구축
  • Express.js 프레임워크를 사용한 웹 애플리케이션 구축

학습 내용

  • HTTP 모듈
    • HTTP 요청 및 응답 처리
    • URL과 쿼리 문자열 파싱
    • 간단한 라우팅 구현
  • Express.js 기본
    • Express.js 설치 및 설정
    • 기본 라우팅 및 미들웨어 이해
    • 정적 파일 제공
const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
  res.send('Hello, World!');
});

app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}/`);
});

 

4주차: 데이터베이스 연결 및 RESTful API

목표

  • MongoDB와 같은 NoSQL 데이터베이스 사용법 익히기
  • Mongoose를 사용한 데이터베이스 연결 및 스키마 정의
  • RESTful API 구축 및 테스트

학습 내용

  • MongoDB와 Mongoose
    • MongoDB 설치 및 기본 명령어 사용
    • Mongoose 설치 및 설정
    • 스키마와 모델 정의
const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true, useUnifiedTopology: true });

const userSchema = new mongoose.Schema({
  name: String,
  age: Number
});

const User = mongoose.model('User', userSchema);

 

  • RESTful API 구축
    • CRUD(Create, Read, Update, Delete) 기능 구현
    • API 엔드포인트 정의 및 테스트
app.get('/users', async (req, res) => {
  const users = await User.find();
  res.json(users);
});

app.post('/users', async (req, res) => {
  const newUser = new User(req.body);
  await newUser.save();
  res.status(201).send(newUser);
});

 

5주차: 비동기 처리와 배포

목표

  • 비동기 처리 심화 학습 (Promise, async/await)
  • 애플리케이션 배포 이해 및 실습

학습 내용

  • 비동기 처리 심화
    • Promise와 async/await을 사용한 비동기 코드 작성
    • 에러 처리 및 디버깅
async function fetchData() {
  try {
    const response = await fetch('https://api.example.com/data');
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Error fetching data:', error);
  }
}

fetchData();

 

  • 애플리케이션 배포
    • Heroku, Vercel 등의 플랫폼을 사용한 배포
    • 배포 시 고려사항 (환경 변수, 보안, 스케일링)
    • 간단한 배포 실습
# Heroku 배포 예제
heroku create my-node-app
git push heroku main
heroku open

 

이 커리큘럼을 통해 Node.js의 기본 개념부터 시작해 실용적인 애플리케이션 구축 및 배포까지 단계별로 학습할 수 있습니다. 각 주차의 학습 내용을 철저히 이해하고 실습해보세요.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

+ Recent posts