Node.JS File Logging - javascript

I want to log stuf into a file, but like with my own logs. I tried to create a Array and just stuff all the logs into it as a own string element and each 10 seconds, it appends the stuff to the file. It actually works fine BUT i have the problem that some logs get written twice. I try to asyncrously start writing the logs to the file and then clear the array to make it ready for new logs. Unfortunately, that creates clones.

There is amazing NPMS for that's you need to save your logs in a .log file.
I use log4js.

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.

Electron Reloading A Specific JS File On Command

I have recently been working on an Electron application which requires the storage of data in a javascript file which gets decrypted when the user logs in and displayed, and encrypted when the user logs out. However, while logged in, the user has the option to add data to the javascript file. Unfortunately though, when this process is complete, the new data is not displayed, despite using the exact same code in the initial display as in the reload. I am confident that this is due to the javascript file needing to be reloaded (file changes are not registered by Electron). I have tried the electron-reload module, but it seems to only allow for live reloads. I need a module or solution which allows me to do something like this.
var reload = require('some-reload-module');
reload.reload('../path/to/file.js');
...
Any solutions would be welcome as I have so far had no luck. Thank you in advance!
This is happening due to the fact that require caches its results in require.cache. To get around this, you can just delete the entry in the cache.
// Initially require the file; the result is cached.
require('../path/to/file.js');
// Delete the cached version of the module.
delete require.cache[require.resolve('../path/to/file.js')];
// Re-require the file; the file is re-executed and the new result is cached.
require('../path/to/file.js');

MongoDB run javaScript file from console and output

I am trying to create some mongoDB script (files upload to collections, find, create new collections etc). Though get confused. When I run in console:
> use importCSV
> db.people.find().pretty()
I get documents from collection on my screen, though when I run load command
> load('e:/work/parse/script.js')
i get output
true
Here javaScript file list
db = db.getSiblingDB('importCSV');
db.people.find().pretty();
I do it for debug purpose, so I create javaScript line by line to get what I want, and I need to see step by step some commands output. If I put to javaScript file command like this
print('Print from javaScript file');
it prints to console without any problems.
Why I get "true" when run from file instead of console output, and how to get list of documents printed when run from javaScript file?
Thanks
This is an expected behaviour. You need to iterate through the cursor and print each document explicitly using a .forEach loop because you are not using the interactive shell.
db = db.getSiblingDB('importCSV');
db.people.find().forEach(function(doc) {
printjson(doc);
}

changes to javascript file "ignored" in VS2010

I have a javascript file harSympCode.js that I am trying to make changes to. It is used in 5 aspx pages - .NET 4.0 & VS2010 - and needs to remain consistent for all 5.
In the js file there is a function startstop() which triggers a floating clock to count. It is called in the onload event of the body tag. It works just fine. There is another function (call it function1()) which is supposed to load some values to a form. It is almost identical to a second one (call it function2()) in the file except the second one does a form.submit() when it is done. I am attempting to modify function1() to also submit the form when done BUT no matter what I do, I can not get the system (VS2010 localhost) to recognize the 2 lines of code I added. Since they are working just fine in function2() and I don't see any error codes or warnings when I rebuild the website, I can only guess that the changes are being ignored.
What I have tried:
Removed the <script> tag from the aspx pages: Result - startstop(), function1() and function2() are not found.
Added the <script> tag back in but removed the script file from the solution/project directory structure: Result - everything runs as if the file was still there.
Deleted sln and suo files and reopened the website while at the same time trying options 1 and 2: Results - same as 1 and 2.
I have looked through my entire directory structure and renamed and/or deleted every version of the js file I could find, to no avail.
I have looked for anything and everything related to precompiling a website (NOT application) and attempted to make changes to a supposed "Precompile" directory but a) could not find the directory and b) all changes I made were ignored and/or reset the next time I went and looked.
Has Anybody seen this and how did you fix it?
This does not seem like an IDE issue as mentioned in your comment. Make sure you set your browser to refresh the cache on each load. In IE:
If you're using Chrome, then cache is cleared from the dev tools and is very persistent. Also refresh the page using CTRL+F5. You also want to make sure that you're not getting compilation errors and your project isn't running from the previous working version. However point 1 of what you've tried suggests that the generated HTML page refreshes when you run your project but your browser cache contains the javascript files and so when the script tag exists it finds the cached ones and executes them. So you can use the 2nd button from the top (Clear Browser Cache...) to remove them.
I had been having this issue, clearing my cache and wondering why VS2010 kept looking at the old file, even though it appeared as the new version in F12.
The solution turned out to be that TFS had the file locked, and that once I checked out the javascript in question, the debugger picked up the new version.

File Exists But Receiving ENOENT Error

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.

Categories

Resources