디버그 부울을 가진 실행 노드/javascript 스크립트가 있는데, true로 설정하면 몇 개의 파일이 작성됩니다. 이 실행 파일은 노드 모듈이기도합니다. 스크립트를 실행하는 사용자의 작업 디렉토리에 따라 함수가 파일을 쓸 디렉토리를 찾을 수없는 것으로 보입니다.모듈 내의 상대 파일 시스템 쓰기 경로
모듈은 경로가 될 수있다하는 것이
output/
lib/
helpers.js
index.js
내 원래 추론과 같이 구성되어있다. node_module 폴더 내에서 스크립트를 실행하는 경우
helper.write = function(data,filename){
if(typeof data !== "string") data = JSON.stringify(data);
fs.writeFileSync("./output/"+filename, data);
};
그러나이 작동하는 모듈이 다른 실행 파일에 사용되는 경우는 더욱 혼란 도착이
node ./my_app/node_modules/the_module/index.js
처럼
fs.writeFileSync("process.cwd()+"/node_modules/the_module/output/"+filename, data);
그 라이브러리를 사용합니다.
node ./my_app/run.js
이러한 모든 변수와 독립적으로 파일을 저장하는 방법이 있습니까?