1. Express.js란Express.js는 Node.js를 위한 가장 인기 있는 웹 프레임워크입니다. 미니멀하고 유연한 설계로 웹 애플리케이션과 API를 빠르게 구축할 수 있습니다.npm install expressconst express = require('express');const app = express();app.get('/', (req, res) => { res.send('Hello World!');});app.listen(3000, () => { console.log('서버 실행 중: http://localhost:3000');});2. 라우팅2.1 기본 라우팅const express = require('express');const app = express();// HTTP 메서드별 ..
분류 전체보기
1. HTTP 클라이언트란Node.js에서 HTTP 클라이언트는 외부 API를 호출하거나 웹 페이지를 가져오는 데 사용됩니다. 내장 http/https 모듈을 사용하거나, axios, node-fetch 같은 라이브러리를 사용할 수 있습니다.2. 내장 http/https 모듈2.1 http.get - 간단한 GET 요청const https = require('https');https.get('https://api.github.com/users/octocat', { headers: { 'User-Agent': 'Node.js' }}, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', ()..
1. Koa.js란Koa.js는 Express.js 팀이 만든 차세대 웹 프레임워크입니다. async/await을 기본으로 사용하며, 더 작고 표현력 있는 미들웨어 구조를 제공합니다. Express보다 가벼우며 내장 기능이 적어 필요한 것만 선택적으로 추가합니다.npm install koaconst Koa = require('koa');const app = new Koa();app.use(async (ctx) => { ctx.body = 'Hello Koa!';});app.listen(3000);console.log('서버 실행 중: http://localhost:3000');2. 컨텍스트(Context)Koa는 요청과 응답을 하나의 ctx 객체로 캡슐화합니다.2.1 ctx 객체const Koa = r..
1. HTTP 모듈 소개Node.js의 http 모듈은 HTTP 서버와 클라이언트를 생성하기 위한 내장 모듈입니다. 별도의 패키지 설치 없이 웹 서버를 구축할 수 있습니다.const http = require('http');const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello, World!');});server.listen(3000, () => { console.log('서버가 http://localhost:3000 에서 실행 중');});2. 서버 생성 방법2.1 createServer 사용const http = require('http');..
