File Exists But Receiving ENOENT Error - javascript

Here is a gist: https://gist.github.com/973e70bde8e6a530c489
I have two scenarios. One works and one fails even though the code is exactly the same.
Take a CSV file already on the box and parse it. Works perfectly. No issues.
Take a CSV file that was just created and attempt to parse it and I receive:
ENOENT, no such file or directory '/Users/Home/dev/csv/TwFrI5vhdownload.csv
Same CSV file format and all that. Wouldn't matter anyway because the created file won't even open. It fails with the error above even though the file does exist. If I restart Node and attempt to grab that file, then it works perfectly. If I run fs.stat on the newly created file it fails.
I've tried timeouts, external callbacks, etc.. but with the dynamically created file it always fails.
What am I missing here? Is the file locked and I don't know it?
Thanks!
System:
OSX Lion
Node v0.6.7

Are you sure the file is actually created when you try to parse it?
I took a look on the gist and I guess you are downloading the file from somewhere and then parsing it. Without the whole code I can only guess, but I think that you started the download, but you haven't received a clear indication it is there and ready to be parsed.

Related

How to stop audit.json file occurring in node js-winston library

I have a node.js app. And I am logging everything using winston library. My logs are daily saved on my desktop in a file. When my logs are created, there is also an audit.json file that is created automatically with my logs. And this audit.json file is saved in my logs file as well. For every run, an audit.json file is created. I want to stop occurring this audit.json file. How can I do that? Any suggestion? When I click audit.json there is some parameters that are shown such as:
(I don't have internet on my work pc so I have to write on my phone sorry)
"keep" :
"days" : false,
"amount" :5
},
"auditLog:" C:/Users/Desktop/LogFiles/.11cjeoepdwgeudp
"files":[
"date" :"1571727049689",
"name": "path"
"hash" :"054239856656...."
audit.json is an important file used by Winston to create a map of your log files. Without it, you won't be able to use the daily-rotate feature. In order to get rid of it and still use the mentioned submodule, you'd have to modify the code of file-stream-rotator - a module used by Winston. It's responsible for creating this file. You could, for example, implement a database store that would replace the json file.
The file is actually hidden on Linux systems and many users don't even know about it. Since you're using Windows, you could modify file-stream-rotator and add the hidden attribute every time the file is created. It would be much easier to achieve than moving the file map store to a database. This module would be helpful if you decided to solve the problem in this way.

D3.js starter(noob): How to get a D3 example from bl.ocks.org/mbostock working?

I'm completely new to JavaScript and D3.js. I have done some work in recent days, like making appropriate json object for the graph, and wanted to know how to get this example running in particular. Any direction to appropriate links would be great, though I would prefer to get an answer in the form of any missing tags or any details I need to take care of.
Note: I have to run it locally, not on server-client model.
Update: I have done it a lot of times what Bill answered, it didn't work. So I tried again and I opened the console in browser to check for any errors. Got this:
Failed to load resource: file://d3js.org/d3.v3.min.js
net::ERR_FILE_NOT_FOUND
index.html:23 Uncaught ReferenceError: d3 is not defined
The point is that you cannot access files on your computer from javascript using file:// (think that people could access all your file...).
So you have to use <script src="address/d3.js"></script> here, address correspond to the address of your server (http://domain.com or http://localhost) or the relative path.
For example, you can download d3.js next to your html file (same folder) and just type <script src="d3.js"></script>
Hope this helps
You can do the following:
Go to https://gist.github.com/mbostock/4062045
Click on the Raw button next to index.html
Copy everything and paste it into a file on your computer called index.html
Go back and click on the Raw button next to the .json file
Copy everything and paste it into a file on your computer called miserables.json (make sure this file is in the same folder as index.html)
Double click on index.html, it should open in your browser

Upgrading from Ractive.js v0.5.8 to v0.7.1 and making a call to file Ractive.js.map

I am upgrading an application from Ractive JS v0.5.8 to v0.7.1 and in the browser console, I am getting a 403 (Forbidden) request calling:
http://[mydomain.com]/www/RACTIVE/ractive/.gobble-build/02-babel/1/Ractive.js.map
What is causing this request, and how do I remedy it?
That's odd - the final line of ractive.js (and the other files) is this:
//# sourceMappingURL=ractive.js.map
In other words, an instruction for the browser to fetch the sourcemap if the console is open, and use that for debugging.
The request you're seeing is for a file that was generated during the build process. We'll remove those intermediate sourcemap comments in the next release (the bundling tool, esperanto, has an open issue for this), but in the meantime it looks like that final comment is being stripped out of the file you're using somehow?
Three things that should fix it:
ensure that the comment shown above is present in your copy of ractive, and place the sourcemap alongside it, or
use the minified version, which doesn't have those comments, or
manually remove the comments (find and replace /\/\/# sourceMappingURL=.+/ with empty lines
If the correct comment is present at the end of the file you've using, I'd be curious to know what browser you're in, and how you installed ractive. Thanks

JSZip unzipping error

Trying to handle with JSZip library.
I am having an issue to unzip a file. Here's a plunker demo. As you can see I can successfully zip a content, but when I try to unzip a zipped content I get an error (can be seen in console):
Uncaught Error: Corrupted zip : can't find end of central directory
Any ideas why this happens?
In any case, here's what I am trying to achieve: I have an textarea on my page. Upon click I want to zip textarea content and send zipped data to server. Another call must be able to receive a zipped data, unzip it and replace textarea text with unzipped one. Everything works ok, except unzipping problem.
The generateAsync() method defaults to a base64 output but the loadAsync() method only see a string.
You have two solutions :
change the generated format with `generateAsync({type:"uint8array"}) (see here)
or tell the load method that you are loading base64 content : loadAsync(data,{base64:true}) (see here)
As answered by David has resolved my problem on my local workstation running Windows 10 OS. However it is failed on the Server running RHEL OS.
I have to fix it by switching to yauzl package for unzipping. It is recommended as mention on package's official repository, with specified merge pull 383.

Rechecking a file for updated content

I'm trying to recheck a file on a timed interval. I'm not sure if this can be accomplished, but any help would be greatly appreciated. I understand that as PHP is server-sided, it cannot accomplish my task, so anything with JavaScript is fine.
By rechecking a file, I mean getting a file's contents, but only if it's updated. Somewhat like "if file gets new contents, output them."
If you are checking on a remote file, then the PHP solution would be best: simply send the file and its checksum, then when the checksum changes, the file has been updated.
If you're working with a local file, then (if I'm seeing things right) you'll need a browser with the HTML5 File API. May be a duplicate of this: Check if file has changed using HTML5 File API

Categories

Resources