Node.js Error ENOENT, open “file/path” when nothing has been changed

安稳与你 提交于 2019-12-12 10:35:44

问题


Ok first off... I'm new to Node.js. I'm trying to convert a word document to HTML then scrapping it to obtain the content. Then pump it into an existing engine.

With that being said, everything was running fairly smoothly until today. I just got the fs.writeFile working last night and stepped away from it. This morning without touching it and trying to run it I receive this:

here's the block where the error is being called.

//COPY TEMPLATE AND PASTE
fs.readFile("./Templates/TextBasedEvent.xml", function (err, data){
    if (err) {
        throw err;
    }       
    var contentHolder = data.toString(),            
        contentHolder = contentHolder.replace(/%EVENTNUMBER%/gi, id),
        contentHolder = contentHolder.replace(/%CONTENT%/gi, contents);
    fs.writeFile("./bin/xml/" + id + ".xml", contentHolder, function (err){
        if (err) {
            throw err;
        }
    });
});

Does it have something to do with how the variable is placed in the file path? also the throw err for it just seems weird that it soft returned in between where the variable is.

Thanks!

Edit: The issue was with newline being pulled in, with the variable.


回答1:


There are a few things that might cause ENOENT when writing a file.

  • The destination directory (in this case, E:\Desktop\SniffIt\bin\xml) does not exist.
  • A newline (CR and/or LF) in the filename.

You should be using a proper XML parser to read your input file. This would probably help you avoid the spurious newlines you're getting.



来源:https://stackoverflow.com/questions/21504919/node-js-error-enoent-open-file-path-when-nothing-has-been-changed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!