I am looking for a way to write the logs from NodeJS to a file. I am using fs.appendFile option. Is there a way to keep adding to the file by keeping the file size constant--for example, if the file exceeds 5 MB and a new line comes in, delete the oldest line to accommodate the new line--sort of like in a rolling basis?
Way To Append To File While Keeping the File Size Constant
464 Views Asked by Vignesh Rangaraj At
1
There are 1 best solutions below
Related Questions in NODE.JS
- Using Puppeteer to scrape a public API only when the data changes
- How to request administrator rights?
- How do I link two models in mongoose?
- Variable inside a Variable, not updating
- Unable to Post Form Data to MongoDB because of picturepath
- Connection terminated unexpectedly while performing multi row insert using pg-promise
- Processing multiple forms in nodejs and postgresql
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- How to change the Font Weight of a SelectValue component in React when a SelectItem is selected?
- My unban and ban commands arent showing when i put the slash
- how to make read only file/directory in Mac writable
- How can I outsource worker processes within a for loop?
- Get remote MKV file metadata using nodejs
- Adding google-profanity-words to web page
- Products aren't displayed after fetching data from mysql db (node.js & express)
Related Questions in FILESYSTEMS
- Where exactly is the first data sector on a FAT file system?
- `df` command not capturing entire output in perl
- Is it possible to mount a logical volume without wiping the data?
- Speed up search of remote directories
- How to change the directory file system without losing files?
- Flutter SDK: Files Deleted Automatically (e.g., dart.exe), Errors in Android Studio
- How to store metadata for a UTF-8 text file cross-platform?
- fsck error on boot: dev/mapper/ubuntu--vg-ubuntu--lv: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY
- rouble with mounting Python code to FUSE: No response and prolonged processing ---
- mkfs.erofs erofs: failed to lookup selabel
- How to deny user access MacFuse file system by the really path
- Is it faster to read a file on an NVMe using threads?
- list folders containing mp3 files using the Capacitor Filesystem
- How to use xdg-open in bwrap environment to open dir in the unsandboxed filesystem
- How to provide content of (locally) encrypted files to the iOS and macOS system
Related Questions in FS
- NodejS fs with authentication on accessing shared directory from cloud
- get pdf from axios utility in node.js
- How come my async function is not working in Node JS?
- How to add Numbers In Arrays format if we have a word in 3 files using nodejs
- Can't resolve fs, child_process
- Using await with fs/promises function just exits code with no error
- Issue with loading chunks into the client
- How to find file named something in an folder
- Javascript for loop variable is strange when writing on a file
- NodeJS/JavaScript - Read File by passing command results from child_process as filepath for "fs.readFile"
- How to delete existing file when update post with node js and react js?
- Attempting to upload a file from local to a server via php
- File reading from remote server
- webpack5 polyfill for fs is stubbornly not resolving for an Angular 14 project
- How to polyfill in webpack v5 to be able to use fs in react-app?
Related Questions in APPENDFILE
- Merge text files in Sublime4 like append?
- How to edit specific line in a textfile?
- how to log data into a new file?
- How to generate an id when adding an object in node.js
- How can I write every list from a nested list separately to a file?
- write into json file with fs.append
- nodejs server restart and send the same request when calling appendfile
- File passed to Pipeline B and Read and append content of file shared by pipeline A in jenkins
- Exceljs append row
- NodeJS 'appendFile' not creating file in Docker container
- appendFile() runs before readFile() even though appendFile() is chronologically after the readFile()
- Haskell possible make own type instance of Text
- Append one file into another file
- NodeJS: write to file responses of multiple GET requests in order
- Recombining large chunked zip download in GO
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
If you are open to use a library for your logging instead of appendfile. You could use winston with the Daily rotate file Transport where you can cap the filesize at
5MBor an amount of days or both.I would suggest zipping up the logs and keeping them for a few days/weeks and setting up a cron job or something to delete the old files. If you really want to delete all logs, you could delete on rotate
Normally log rotation is handled by the operating system using something like logrotate