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
1 answer

Nodejs reading and writing to the same file at the same time

I have a node.js application with express which write html files, and sometimes update them. Is it a bad practice or breaking practice to write and read from the same file at the same…
Eran Shmuel
  • 149
  • 2
  • 15
0
votes
1 answer

csv-parser .on('end') nodeJS

I have this function bd() that should return an arrays of all the data read in the file groupes.csv which will be later processed : function bd() { const birthdays = []; fs.createReadStream('./data/groupes.csv') .pipe(csv({})) …
0
votes
0 answers

Display Image whenever an update is detected using JavaScript

I'm currently working on a website that has an image file that is frequently overwritten, but since the website doesn't automatically update the image when it is changed, I'm trying to re-display the image whenever it senses a change in the…
0
votes
1 answer

How to increment values in an array json file based of from a name?

Example JSON file: [ { "discordId": "9273927302020", "characters": [ { "name": "Rare_Character", "value": 1 }, { "name": "Ultra_Rare_Character", "value": 1 } ] } ] Let's just say for example I ran…
rhenzu
  • 5
  • 2
0
votes
1 answer

ffmpeg output always has frozen parts of the output mp4

So a little clarification i have a folder of videos that i want to combine into one. Ive looked at multiple overflows and everything i try ends up with an error. The first few videos work then on the later ones its just frozen. I can still however…
bein
  • 11
  • 3
0
votes
1 answer

Discord.JS Command Handler: How to read files from all directories within a directory?

I am running into some issue with checking the commands directory for my files. I want readdirSync to read all .js files from some directories inside the /commands/ directory (music, info etc.) but I don't seem to know or be able to find a way to do…
nikoszz
  • 163
  • 1
  • 3
  • 13
0
votes
1 answer

How To Append Data In Json Fs.writeFile without updating

Hey i want to append data to my json file but its Acutally updating the old data please help me refine the code 'use strict'; const fs = require('fs'); function handleSubmit(event) { event.preventDefault(); const data = new…
HEALER
  • 31
  • 2
0
votes
0 answers

How to backup a file when a file got edited using nodejs fs module?

I am a beginner to nodejs please help me find this solution? I need code that looks at a file and makes a backup of the file whenever it is changed and saved to the disk. have to create backup in separate folder. filenofoundexception if no…
storm
  • 43
  • 8
0
votes
1 answer

copyFile with node occasionally only copies part of file

I'm trying to build a file watcher that copies files when they are finally added using chokidar. The files have differing sizes, but range between 200MB and 1GB. watch(`${inputFolder}/*/**`, { ignoreInitial: false, awaitWriteFinish:…
prohit
  • 609
  • 1
  • 6
  • 18
0
votes
0 answers

Node fileSync() returning incorrect size on Windows due to newline differences

I want to find the size of a text file in bytes, however, the standard method of fs.statSync("/path/to/file") returns the incorrect size, seemingly due to newlines. For example, a 461 byte file with 5 Unix-style \n newlines shows 466 bytes,…
0
votes
1 answer

Nodejs Express PM2

im running an express api on a vm with nodejs and using pm2. I have a function running on setInterval and running every 30 seconds, the function gets data from an external api and then im concatenating the fetched data from the interval to the…
Bull
  • 3
  • 2
0
votes
1 answer

How to stream different local videos using NodeJS and Express

I would like to stream different user-selected videos to my front-end. For this I am using NodeJS and Express. The source of the -element in which the video should be displayed is 'http://localhost:4201/video'. The code I am using to stream the…
GyroGoober
  • 61
  • 8
0
votes
1 answer

I keep trying to use require to load in node fs module and it keeps giving me invalid callback error, how do i rectify this

Here is the sourcecode: console.log('Starting app.'); const fs = require('fs'); fs.appendFile('greetings.txt', 'Hello world!'); fs.appendFileSync('greetings.txt', 'Hello world!'); when i load the app in the terminal, it keeps giving me this…
Vally
  • 1
0
votes
1 answer

How to "create" a file in NodeJS v16

I tried making an evaluate command with discordjs and im trying to log the code in a file. This is my code rn: const { Client, MessageEmbed, MessageAttachment } = require('discord.js'); const axios = require('axios'); const fs = require('fs'); const…
0
votes
1 answer

Merging several JSON files in TypeScript

I am currently tasked with finding the amount of times a specific email has contacted us. The contacts are stored in JSON files and the key should be "email". The thing is there are potentially infinite JSON files so I would like to merge them in to…
1 2 3
99
100