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

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.

Related

Error BLAZOR106 when saving Javascript/TypeScript file with the same component's name

I have a .Net6 Blazor Server Side project.
I created a component called HomePage.razor, another one called HomePage.razor.cs and a TypeScript file called HomePage.razor.ts. This way, I get a nice visual of the HomePage.razor in the solution explorer, as the "child" files nest in it.
When I save my TypeScript file, the file wwwroot\Pages\HomePage.razor.js is automatically generated, and I refer it at my _Host.cshtml.
Also, as soon as I save it, I get the error BLAZOR106 - The JS module file 'c:\...\wwwroot\Pages\HomePage.razor.js' was defined but no associated razor component or view was found for it.
If I change the name of my TypeScript file from HomePage.razor.ts to anything else - like HomePage.ts - save it, and delete the old generated JS file at wwwroot, everything works fine. But this way, I lose the nice "collapsing by name" in the solution explorer that VS2022 provides.
I couldn't find any content related to the BLAZOR106 error (Google and Microsoft documentation), so I wonder if you know how to solve this issue.
Thanks.
I was getting the same error but in my case I wasn't even using a razor component, just a razor page .cshtml file. Similar to you, I also had a .cshtml.cs and .cshtml.js file because I like the organization of that.
Pages/Index.cshtml
Pages/Index.cshtml.cs
Pages/Index.cshtml.js
Originally I was using a bundleconfig.json to minify in place.
Pages/Index.cshtml.min.js
Pages/Index.cshtml.min.js.map
Then I used libman to copy the js files into:
wwwroot/js/Pages/Index.cshtml.js
wwwroot/js/Pages/Index.cshtml.min.js
wwwroot/js/Pages/Index.cshtml.min.js.map
As you can see, I was not using razor components or Blazor anywhere in my application. And this worked fine when targeting .NET 5
I upgraded to .NET 6 and I started getting the same error you are getting.
Background magic is going on here that the aspnet team should address but in the meantime my workaround was to remove the .cshtml. part from the file name in wwwroot.
wwwroot/js/Pages/Index.min.js
wwwroot/js/Pages/Index.min.js.map
To achieve this, I changed my bundleconfig to output directly to those files and I removed the libman part. It actually made more sense than what I was doing before because I only care that the original Index.cshtml.js file is nested.
bundleconfig.json
{
"outputFileName": "Pages/Index.cshtml.min.js",
"inputFiles": [
"Pages/Index.cshtml.js"
]
}
libman.json
{
"provider": "filesystem",
"library": "Pages/Index.cshtml.js",
"files": [
"Pages/Index.cshtml.js",
"Pages/Index.cshtml.min.js",
"Pages/Index.cshtml.min.js.map"
],
"destination": "wwwroot/js/"
}
To just this:
bundleconfig.json
{
"outputFileName": "wwwroot/js/Pages/Index.min.js",
"inputFiles": [
"Pages/Index.cshtml.js"
]
}

WebStorm's Autocomplete not working for one exact file (treated as plain text)?

My WebStorm's autocomplete stopped working today.
I made a new component and wanted to call it ProductArticleManager as it's the most fitting name for it.
However, the Autocomplete for that single file just refuses to work. Looks like the IDE can't recognize it as a JS file.
I also made another folder called NewComp and made a component NewComp.js to check if it has anything to do with filename matching the folder name, but NewComp.js works fine.
Is there something wrong with this particular name?
What i already did after a little googling:
Restarted the IDE and computer, of course.
Checked that Power Saving Mode is off.
Tried File => Invalidate Cache / Restart option.
Right clicked on the root folder and set it as Resource Root.
Renaming the working test.js file to ProductArticleManager.js turned off the Autocomplete.
Moving the entire folder to another folder.
Deleting ProductArticleManager folder and re-creating it didn't work either.
I work in Ubuntu v20.04, WebStorm v2020.3.
Looks like the file is treated as plain text.
Please check the registered patterns in Settings | Editor | File types -> Text and Auto-detect file type by content file types - can you see ProductArticleManager.js there? Removing this pattern from the list should help

React JS - Reading environment configurations from external property file

Problem :
I am new to React JS, and looking for an option to read environment configs from an external property file. This problem is more specific for one of my clients, who is looking to have an option to change the environment files dynamically. E.g. change the hostname/port dynamically whenever there is a change. The build process is not owned by my client. I create a minified final package, which my client deploys it on tomcat/web server.
Tried Solution :
With some read-outs, I have configured .env files for different environments and able to successfully read configs from these files. However, these are more of a build process environment files. And, I am trying to find a way to read the configs from an external source after my package is created.
Possible solutions : Here is one possible approach I can think of -
Read external property file using libraries like "properties-reader". I will provide the property file as part of my release bundle (i.e. build folder). My client can change this property file whenever required.
Please suggest if this is the correct approach or is there a better solution to this problem?
A Solution which worked for me !!
1) Create a "config.js" file inside public folder of react project. Sample Content of the
"config.js" file -
window.env = {
API_DOMAIN_ADDR: "http://localhost:8080"
};
2) Refer "config.js" file inside index.html. Code for index.html will be -
<body>
<div id="root"></div>
<script src="%PUBLIC_URL%/config.js"></script>
</body>
3) Now, content of the config.js file will be accessible to react code. Sample code to retrieve the value of config.js variables -
window.env.API_DOMAIN_ADDR
Add this code wherever variable value needs to be accessed. I added this in my service class which is making ajax call.
I would suggest using something like Firebase Realtime DB. I had a similar requirement for pointing the App builds to production or development server APIs for my company. For this, we use to load a Firebase Config and from there the UI used to pick up the host server endpoint.
Advantages:
This saves you from deploying your build folder every time.
This is realtime and less prone to errors.
FirebaseDB is free for small stuff like this.
The second option is to create two environment files which I see you have already done.

How to distinguish a file from a folder while uploading using drag and drop in jquery?

If a user tries to drag and drop a folder to my file uploader control for uploading it, then I need to show an error message to the user saying that only files can be uploaded. The problem is I couldn't distinguish a file from a folder.
One way I thought was to check for file type property of jQuery. Supposing that the name of the file is "test.txt", then file type would return "text/plain". For a normal folder name such as "TestFolder", file type would be blank and its file size would return 0. However if the folder name included an extension like "TestFolder.txt", then file type would return "text/plain".
So I could have checked for file type and file size but it would not work correctly for folder name like "TestFolder.txt". Could any one suggest me a good solution to fix this using jQuery or other methods?
The ability to determine if a folder has been dropped is dependent on the user agent's support of the Filesystem API. If the user agent DOES support the Filesystem API (currently only Chrome 21+), you can make use of the Entry interface, which has two child interfaces: DirectoryEntry and FileEntry. The interface itself has isDirectory and isFile functions. Without support for this interface, there is no way to determine if dropped items are folders when examining the DataTransfer object.
Since you are not going to allow folder to drag and drop, first check if it's folder or file, second only if it's not folder then check for file extension. But IE < 11 does not support file API to handle. Hope it helps.
As far as I'm aware the browser (And javascript inherently) doesn't have access to any file access methodologies for security purposes so you cannot check what the file actually is.
I have worked with this problem myself in the past and the best option I have found that works is to handle the file server-side, and return the error back to the page after upload has completed.
I would be happy to see better alternatives myself though.

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