__dirname vs process.cwd()

이동규 (Justin)·2021년 4월 1일
0

무슨 차이일까?

Nodejs 문서를 살펴보면..

process.cwd()

It returns the current working directory of the Node.js process.

__dirname

The directory name of the current module.


둘은 모두 경로를 출력하는 함수이나 그 '스코프' 가 다르다는 것을 눈치챌 수 있다.

process.cwd() 는 Nodejs 프로세스가 돌아가고 있는 Working directory를 출력하는 반면, __dirname은 해당 모듈의 경로를 출력한다.

profile
Frontend Developer, JamStack, Ethereum

0개의 댓글