美文网首页我爱编程
fs 读不到路径下文件 express

fs 读不到路径下文件 express

作者: Haydn | 来源:发表于2018-04-16 01:01 被阅读0次

    https://stackoverflow.com/questions/48469666/error-enoent-no-such-file-or-directory-open-moviedata-json

    fs.readFileSync('moviedata.json', 'utf8') will look for moviedata.json in the directory from where you ran your application, not in the directory where your MoviesLoadData.js file is located.

    Suppose you ran node aws/MoviesLoadData.js from /Users/dortiz/Documents/NodeJS/pruebas/zw, fs.readFileSync('moviedata.json', 'utf8') would look for moviedata.json in /Users/dortiz/Documents/NodeJS/pruebas/zw, not in /Users/dortiz/Documents/NodeJS/pruebas/zw/aws

    If you were to run your script with my given example, you'd need to prepend the path to the json file to correctly reference it.

    fs.readFileSync(__dirname + '/moviedata.json', 'utf8')
    

    I'm not sure how you run your code, so my example may not work in your codebase, but hopefully understanding where you went wrong will help debug your code.

    相关文章

      网友评论

        本文标题:fs 读不到路径下文件 express

        本文链接:https://www.haomeiwen.com/subject/spfskftx.html