상세 컨텐츠

본문 제목

Node.js / path 모듈

프레임워크+라이브러리/Express

by moonionn 2020. 7. 23. 22:25

본문

const path = require('path');
const { dirname, basename } = require('path');

const directories = ['Users', 'UserName', 'Desktop'];

const dirStr = directories.join(path.sep);
console.log(`directory(String) = ${dirStr}`);
//result: Users/UserName/Desktop

const filePath = path.join('Users/UserName', 'Desktop', 'practice.js');
console.log(`file path = ${filePath}`);
//result: Users/UserName/Desktop/practice.js

const dirName = path.dirname(filePath);
console.log(`directory of this file = ${dirName}`);
//result: Users/UserName/Desktop

const baseName = path.basename(filePath);
console.log(`name of this file = ${baseName}`);
//result: practice.js

const extName = path.extname(filePath);
console.log(`extension of this file = ${extName}`);
//result: .js

 

도움: https://www.youtube.com/watch?v=4DPdcfbGSps&list=PLG7te9eYUi7tHH-hJ2yzBJ9h6dwBu1FUy&index=7

 

관련글 더보기

댓글 영역