Questions tagged [fs]

File I/O in the Node.js Javascript platform

File I/O in the platform.

The fs module provides an API for interacting with the file system in a manner closely modeled around standard POSIX functions.

To use this module:

const fs = require('fs');

All file system operations have synchronous and asynchronous forms.

The asynchronous form always takes a completion callback as its last argument. The arguments passed to the completion callback depend on the method, but the first argument is always reserved for an exception. If the operation was completed successfully, then the first argument will be null or undefined.

Documentation.

2942 questions
0
votes
0 answers

fs unlink not deleting video untill server restart

So this is my code fs.unlink(`storage/videos/${videoId + path.extname(file.originalname)}`, err => { if (err) return console.log(err) console.log(`deleted video: ${videoId + path.extname(file.originalname)}`) }) This thing console logs the…
eldernyPro
  • 11
  • 2
0
votes
0 answers

Node File System unstable

In Node.js, I noticed that file operations were not always stable. I have the impression that fs gives up when the operations are not completely finished. Here is an example to illustrate: "use strict"; Error.stackTraceLimit = Infinity; const fs =…
user3515941
  • 141
  • 1
  • 8
0
votes
3 answers

fs.readFileSync doesn't recognize file

The fs.readFileSync function does not recognize the HTML-file, even tho it is localted in the same folder. The error says: Error: ENOENT: no such file or directory, open 'node.html' const http = require('http'); const PORT = 3000; const fs =…
0
votes
0 answers

this is impossible to inculde fs library

here i want to use fs library at the js file to create and edit a json file. but whenever i include this namespace an strange error comes up. if i use var fs = require("fs") it throws the error: Uncaught ReferenceError: require is not defined if i…
0
votes
1 answer

How to read file names and display names to window node js

I'm wondering how I'd be able to read file names from my directory and be able to display them in table form to a window. I already have an attempt I made below but for some reason whenever I run the code all it displays on the window is the word…
Ewgavin
  • 13
  • 2
0
votes
1 answer

How to find tmp folder made by nodejs filesystem?

I was using fs to write values from textarea into a file and had issues with the path until I found on stackoverflow that the path has to be a tmp folder. I did that and the terminal shows the function was successful but now I don't know where that…
0
votes
0 answers

Why am I getting a warning to run fileHandle.close()?

I'm running a nodeJS program, which initially reads a db, and then writes to it, through several iterations of a for loop (async ()=>{ const db = JSON.parse(await fs.readFile(DB_URL)); // ... more code for(let i = 0; i < n /*n in the range of…
sayandcode
  • 1,775
  • 1
  • 11
  • 24
0
votes
2 answers

How to write multiple lines to a text file in a loop?

Within a javascript function, I'm taking in a list of events and for each event, I would like to write text to a file. I have provided the correct // Code within another function events.map(event => { const start = event.start.dateTime ||…
ENV
  • 877
  • 2
  • 10
  • 32
0
votes
0 answers

I want to write log file for AngularJS project. How can I do it?

I tried this method : var fs = require("fs"); //or try //var fs = require("file-system"); var cont = " selamm \n"; fs.writeFileSync("read2.txt", cont, { flag: 'a' }, err => { }); Not working for Angular JS project. System err : "fs is…
0
votes
0 answers

Why is createReadStream not updating a variable?

I am using fs.createReadStream to read CSV data and it is exhibiting some weird behaviour. I'm very confused as to why this is happening. I have the following code: const result = [] fs.createReadStream("path") .pipe(csv()) //csv parser …
Ammar Ahmed
  • 344
  • 3
  • 11
0
votes
1 answer

How to move groups of files in Nodejs

I have a folder with 600 files in it and I want to group them into subgroups of 127 files, each in their own folder. I've managed to work out how to create the folders, but I can't figure out how to move each subgroup of 127 into their corresponding…
0
votes
1 answer

fs.readdirSync alternative for my Web-App

I have a big problem and I hope someone can help me. Some time ago I created a "Desktop App" with Electron, consequently, I was able to freely use the "file-system" library but now I need to transform this Electron App into a sort of WebApp that…
0
votes
0 answers

Clear content of file after downloading

I try to save file on desktop and clear it after saving inside my application. I use Node.js and Express in my application. I got data from MongoDB and use fs.appendFile to save neccessary data to file. Then I use button to download saved…
Andy
  • 79
  • 7
0
votes
0 answers

Moving directories with subdirectories using `moveSync` from `fs-extra`

I have 2 paths: app/consultants/pages/assignments app/consultants/pages/consultants Both paths contain subdirectories and files. I created a reduce function that returns an array of objects with the following structure: [{ model: 'consultants', …
Dileet
  • 2,034
  • 3
  • 33
  • 53
0
votes
1 answer

How do I modify JSON files while keeping the state updated?

If I have a program as follows to modify a JSON file: var fs = require('fs'); var dt = require('./dataWrite.json'); console.log("before",dt); fs.readFile('./data.json', 'utf8', (err, data) => { if (err) { throw err; } else { …
Vayun
  • 95
  • 1
  • 10