fs.readFileSync is Not File Relative? Node.js

前端 未结 1 1945
终归单人心
终归单人心 2020-12-22 21:11

-Suppose I have a file in the root of my project called \"file.xml\"

-Suppose I have a test file in tests/ called \"test.js\" and it has

const file =         


        
相关标签:
1条回答
  • 2020-12-22 21:33

    You can resolve the path relative the location of the source file - rather than the current directory - using path.resolve:

    const path = require("path");
    const file = fs.readFileSync(path.resolve(__dirname, "../file.xml"));
    
    0 讨论(0)
提交回复
热议问题