Skip to content

Tag: fs

Unable to remove data from json file on disk

I’m unable to find a way to remove whole line of JSON data(line) after it’s used. For some reason delete is not working or rather said not doing anything. .JSON code The goal here is to select random code, which is done but then I need to remove it from .JSON file so it won’t repeat. I tried…

Get file type using fs/node.js

I have a folder with few files and I need to get type/extension of the file matching with the number I generate in my num variable, so is there any way I can do it? My current code is: files variable return this: [‘1.jpg’, ‘2.png’, ‘3.gif’] Answer To find a file in a list o…

Count all files with specific type in folder

I’m kinda new to coding, and I need to count files with specific type in my folder, but I don’t know how to do it using fs module! My current code: Can someone help me? Answer You can use path.extname like this: Also, as mentioned by MegaMix_Craft, take care about the variable yourExtension. It ha…

Adding Numbers from csv

I am trying to add all numbers from an column to an variable. The Problem is my code is adding the String to which results into NaN. gives me : “0Daily Device Installs00001000101100” and if I add parseInt(csvrow[2]) I will get NaN for test. My goal is to add all numbers after Daily Device Installs…

fs.writeFileSync method writing wrong to a text file

I have a problem with my script related to writing to a text file. The logic flow works as follows: I read an entire unformatted text file with fs.readFileSync and pass all the read content to a variable of type string. After that I use the .split to break this text into several parts and keep each part of th…