path : 파일 경로나 디렉터리 경로를 다루는 모듈
-운영체제 간에 경로 구분자를 통일 (윈도우 : 역슬래시(\), MacOS와 리눅스 : 슬래시(\))
-새로운 경로를 만들거나, 가져온 경로 정보를 분해해서 한 정보만 꺼냄
ch03 - <path.js>
-join() : 입력한 경로를 하나의 경로로 연결
-dirname() : 파일 이름을 제외하고 경로만 출력
-basename() : 경로를 제외하고 파일 이름만 출력
-extname() : 파일 확장자만 출력
-parse() : 경로를 각각 객체로 반환해서 출력
const path = require("path"); //path 모듈 가져오기
const joinPath = path.join("some", "work", "ex.txt"); //join 함수 : 입력한 경로를 연결
console.log(`join : ${joinPath}`);
const dirnamePath = path.dirname(joinPath); //dirname 함수 : 파일 이름을 제외한 경로만 출력
console.log(`dirname : ${dirnamePath}`);
const basenamePath = path.basename(joinPath); //basename 함수 : 경로에서 파일 이름만 출력
console.log(`basename : ${basenamePath}`);
const extnamePath = path.extname(joinPath); //extname 함수 : 파일 확장자만 출력
console.log(`extname : ${extnamePath}`);
const parsePath = path.parse(joinPath); //parse 함수 : 경로를 각각 객체로 분해해 반환
console.log(parsePath);
>> node path
'Do it Node.js > EJS BackEnd' 카테고리의 다른 글
6. 버퍼, 스트림, 파이프 (0) | 2024.02.28 |
---|---|
5. fs 모듈 (0) | 2024.02.27 |
3. 모듈 시스템 (0) | 2024.02.24 |
2. 자바스크립트 비동기 처리 (0) | 2024.02.23 |
1. node.js, npm (0) | 2024.02.22 |