You need to enable JavaScript to run this app.
Progress Not Perfection
[Node.js] __dirname, path.join
March 04, 2021
__dirname
파일에 _filename, _dirname을 넣어두면
실행을 할 때의 파일명과 경로로 바뀌어서
나타난다. 즉 절대경로를 알려주는 환경변수.
path.join([path])
path.join 을 사용해서 인자들끼리 이어준다.
path.join(‘/foo’, ‘bar’, ‘baz/asdf’, ‘quux’, ’..’); //‘/foo/bar/baz/asdf’
path.join(‘foo’, {}, ‘bar’); //Throws ‘TypeError: Path must be a string. Received {}’
path.join(__dirname, “/test1”)
이런 식으로 붙임
출처
__dirname
path.join
Share on Twitter
Written by
Sunmin
어제보다 나은 오늘을 만들기 위해 배우고, 기록하고, 회고합니다. Maker. Reader. Realistic optimist.
← [CS] 절대경로, 상대경로
[JS] 접근자 프로퍼티와 getter, setter →