javascript - Node.js sporadically failing to write file with: Error: ENOENT, open 'filename' -
I am working on a node.js application which accesses the file system. In my trial, I've noticed something very strange that Google is not able to answer for me.
My code works up to 95% of the time, however, on occasion, I get this error: "Error: ENOENT, open 'test.Q3rax'" where test.Q3rax generates a random File name is That file should be writable, and if I run my code again, in which the file name is hard, then it works fine.
Here is the code where this has failed:
NPJSON.protipip.litefile = function {new data} {if (loaded!!) (Error!): Error: NPJSON The written file () was called before any data was loaded. "; Var stringToWrite = JSON.stringify (new data); Fs.writefile (this.fileName, stringToWrite, function (mistake) {if throw (mistake) throw;}); };
Edit: For clarification, I am generating random file names like this:
var filename = 'test.' + GetRandomText (5,6); Function getRandomText (numberOfCharactersLow, numberOfCharactersHigh) {var numbChar = getRandomInt (numberOfCharactersLow, numberOfCharactersHigh); Var possible = "ABCDEFGHIJLLMNOPQRTUVWXAABDFGILMNNAPCrustWwox 1234567890"; Var returnText = ''; (Var i = 0; i & lt; numbChar; i ++) {returnText + = possible.charAt (getRandomInt (0, 62)); } Return return text; } Function getRandomInt (minimum, maximum) {return Math.floor (Math.random () * (max - min + 1)) + minute; }
It is possible that you are not filing files in the node with written asynchronous Written O_SYNC
means that you are trying to access the file before flushing it into the disk by the kernel. Here's a little bit more read here (under header fs.writeFile ()
):
Edit : To display this problem forcibly An example is:
Comments
Post a Comment