3,196 questions
0
votes
1
answer
50
views
Does fs.watch in Node.js listen to changes in hidden folders like .git?
If I watch a directory that has a .git inside of it and run fs.watch, does that listen to changes within .git folder?
For example if I use:
fs.watch(dir, { recursive: true }
2127
votes
19
answers
2.2m
views
Writing to files in Node.js
I've been trying to find a way to write to a file when using Node.js, but with no success. How can I do that?
682
votes
34
answers
923k
views
How to download a file with Node.js (without using third-party libraries)?
How do I download a file with Node.js without using third-party libraries?
I don't need anything special. I only want to download a file from a given URL, and then save it to a given directory.
-5
votes
1
answer
119
views
Why is arr undefined even though function returns an array? [duplicate]
const randomGIFFunc = async function(dirname) {
const dirPath = 'src/gifs/' + dirname;
fs.readdir(dirPath, (err, files) => {
if (err) {
console.log('Error reading directory: ', err );
...
797
votes
18
answers
871k
views
How to append to a file in Node?
I am trying to append a string to a log file. However writeFile will erase the content each time before writing the string.
fs.writeFile('log.txt', 'Hello Node', function (err) {
if (err) throw err;...
3
votes
2
answers
339
views
How to fsync a directory?
I have a write-ahead log that stores some metadata using atomic renames. Currently I am only fsyncing the file before rename, but it is my understanding that I should also be fsyncing the directory ...
480
votes
12
answers
356k
views
Get file name from absolute path in Nodejs?
How can I get the file name from an absolute path in Nodejs?
e.g. "foo.txt" from "/var/www/foo.txt"
I know it works with a string operation, like fullpath.replace(/.+\//, ''),
but ...
235
votes
12
answers
309k
views
Using filesystem in node.js with async / await
I would like to use async/await with some filesystem operations. Normally async/await works fine because I use babel-plugin-syntax-async-functions.
But with this code I run into the if case where ...
87
votes
24
answers
139k
views
Get all files recursively in directories NodejS [duplicate]
I have a little problem with my function. I would like to get all files in many directories. Currently, I can retrieve the files in the file passed in parameters. I would like to retrieve the html ...
0
votes
1
answer
65
views
How does the close event handler for a readable stream in node.js get called?
I'm having trouble understanding the following code:
const fs = require('fs')
const readableStream = fs.createReadStream(__filename)
readableStream.close()
readableStream.on('close', () => {
...
0
votes
0
answers
42
views
How to mount a subdirectory(inode ) to a specific path? Kernel development
I'm working on a directory-level snapshot feature based on a file system, where a snapshot of a directory is recorded by an inode, and I want to implement how the snapshot sharing mount should be ...
4
votes
1
answer
328
views
Error packaging electron app that uses local files
I created an App using electron that interacts with local files using IPC. When i run it using npm start, éverything works as excpected, but when i try to package the app into an .exe file using the ...
44
votes
9
answers
69k
views
How to disable warnings when node is launched via a (global) shell script
I am building a CLI tool with node, and want to use the fs.promise API. However, when the app is launched, there's always an ExperimentalWarning, which is super annoying and messes up with the ...
0
votes
1
answer
58
views
Why Can This Not Write To Directory 'Output'?
I am attempting to write a file to an existing directory, using node, path, and fs.
How it's supposed to work:
Init mock data.
Loop through mock data.
Write mock string to existing directory 'output'
...
1
vote
1
answer
78
views
fs.writeFile adds extra brackets to json of key=>values object in node.js
I'm trying to update one JSON file in a for loop called asynchronously. Each time I update the whole file, with 1 object.
This is my very complex code after half a day of research. (I know it's too ...
151
votes
5
answers
191k
views
Writing JSON object to a JSON file with fs.writeFileSync
I am trying to write a JSON object to a JSON file. The code executes without errors, but instead of the content of the object been written, all that gets written into the JSON file is:
[object Object]...
2
votes
1
answer
3k
views
Why the import * as fs from 'fs' doesn't work and gives me an error?
So this is my problem:
import * as fs from 'fs';
var downloads = 0;
const fs = require('fs')
fs.readFile('tp.txt', (err, inputD) => {
if (err) throw err;
downloads = inputD.toString();
})...
14
votes
2
answers
8k
views
How can i save a file i download using fetch with fs
I try downloading files with the fetch() function from github.
Then i try to save the fetched file Stream as a file with the fs-module.
When doing it, i get this error:
TypeError [...
25
votes
5
answers
101k
views
Module not found: Error: Can't resolve 'fs' in React
I want to implement a SASS compiler for my online editor, for this I want to use the npm package "node-sass".
However I get the error
Module not found: Error: Can't resolve 'fs' in '<...
47
votes
15
answers
136k
views
Node fs Error: EPERM: operation not permitted, open
I get this error in my app:
Error: EPERM: operation not permitted, open 'C:\Program Files
(x86)\Full Menu\db\main.json'
The app I have is built with electron-boilerplate. I am using this function ...
2
votes
1
answer
338
views
How to get rid of warning "lint TP1004 fs.existsSync(???*0*) is very dynamic" in nextjs 14.2.5 server
Using nextjs 14.2.5, in one of the server component, I need to save a temp file to server storage, the code works fine, but every time the server component is called, there's the this warning
lint ...
0
votes
1
answer
1k
views
Module not found: Can't resolve 'fs' in nextjs
In my project there is an one dependency better-sqlite3.
This dependency is working fine.But after some time i am getting the fs module not found error again and again.
I tried all the methods like ...
1
vote
0
answers
59
views
Can Nodejs fluent-ffmpeg process opus file stream in async way?
What I want to do:
load a large opus file
processing it using fluent-ffmpeg
output a stream for further use (realtime output is required)
Runnable codes(file path needs to be changed):
const fs = ...
0
votes
2
answers
4k
views
How to update a JSON file for a Playwright test
I have a JSON file that contains a value that I need to update as a step of a Playwright test as well as containing other values that need to remain unchanged. I have found a solution but it's not ...
0
votes
1
answer
85
views
Convert file of consts to string and save it in fs
I'm newbie with electronjs so i tried to save my file as a TXT file via fs like this:
simple consts in
data.ts file:
export const users = [{ id: 1, name: 'a', classId: 1 }]
export const classes = [
...