简体   繁体   English

Node.js错误ENOENT,当没有任何更改时打开“文件/路径”

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

Ok first off... I'm new to Node.js. 好的,先关闭......我是Node.js的新手。 I'm trying to convert a word document to HTML then scrapping it to obtain the content. 我正在尝试将word文档转换为HTML,然后将其删除以获取内容。 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. 我刚刚让fs.writeFile在昨晚工作并离开了它。 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. 编辑:问题是使用变量拉入换行符。

There are a few things that might cause ENOENT when writing a file. 在编写文件时,有一些事情可能导致ENOENT

  • The destination directory (in this case, E:\\Desktop\\SniffIt\\bin\\xml ) does not exist. 目标目录(在本例中为E:\\Desktop\\SniffIt\\bin\\xml )不存在。
  • A newline (CR and/or LF) in the filename. 文件名中的换行符(CR和/或LF)。

You should be using a proper XML parser to read your input file. 您应该使用正确的XML解析器来读取输入文件。 This would probably help you avoid the spurious newlines you're getting. 这可能会帮助您避免您获得的虚假换行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM