분류 전체보기

·Node.js
1. 이벤트 모듈이란events 모듈은 Node.js에서 이벤트 기반 프로그래밍을 구현하기 위한 핵심 내장 모듈입니다. Node.js의 많은 내장 모듈(http, fs, stream 등)이 이 모듈을 기반으로 동작합니다. 이벤트를 발생시키고(emit) 리스너를 등록하여(on) 비동기 작업을 처리하는 패턴을 제공합니다.2. EventEmitter 기본 사용법2.1 EventEmitter 생성const EventEmitter = require('events');// 방법 1: 직접 인스턴스 생성const emitter = new EventEmitter();// 방법 2: 클래스 상속class MyEmitter extends EventEmitter {}const myEmitter = new MyEmitter(..
·Node.js
1. path 모듈이란path 모듈은 파일과 디렉토리 경로를 다루기 위한 Node.js 내장 모듈입니다. 운영체제마다 경로 구분자가 다른데(Windows는 , POSIX는 /), path 모듈을 사용하면 운영체제에 관계없이 일관된 방식으로 경로를 처리할 수 있습니다.2. path 모듈 불러오기// CommonJSconst path = require('path');// ES Modulesimport path from 'node:path';3. 경로 정보 추출3.1 path.basename()경로에서 파일명을 추출합니다.const path = require('path');console.log(path.basename('/home/user/file.txt'));// file.txtconsole.log(path..
·Node.js
1. URL 모듈이란url 모듈은 URL 문자열을 파싱하고 조작하기 위한 Node.js 내장 모듈입니다. URL의 각 구성 요소(프로토콜, 호스트, 경로, 쿼리 파라미터 등)를 분리하거나 조합할 수 있습니다. Node.js는 레거시 API와 WHATWG URL API 두 가지를 제공합니다.2. URL의 구조https://user:pass@www.example.com:8080/path/page?query=value#hash │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └─ hash (fragment) │ │ │ ..
·Node.js
1. HTTP 모듈이란http 모듈은 Node.js에서 HTTP 서버와 클라이언트를 생성하기 위한 내장 모듈입니다. 별도의 웹 프레임워크 없이도 HTTP 서버를 구축할 수 있으며, Express.js 같은 프레임워크도 내부적으로 이 모듈을 기반으로 동작합니다.2. HTTP 서버 생성2.1 기본 서버const http = require('http');const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' }); res.end('안녕하세요, Node.js HTTP 서버입니다!');});server.listen(3000, () => { console.log(..
wsstar
'분류 전체보기' 카테고리의 글 목록 (10 Page)