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

What's the equivalent to chattr in the rust standard library?

I need to execute the equivalent of chattr +i myfile.txt in rust. Since the call for chmod is fs::set_permissions() I was expecting something like fs::set_attributes() to also exists, but I cannot find it in the docs. Is there an std function to set…
NerdEngine
  • 363
  • 4
  • 11
0
votes
0 answers

Simple NodeJS minifier cli app - fs.writeFile only writes to 1 file from list over and over

As my first NodeJS app I made a simple CLI Minifier app for HTML, CSS and Javascript files. It works for the most part but one feature. The goal is to have the "all" command read all files in a folder, put the names in an array and write those files…
0
votes
1 answer

Use fs promise to move a file

I have a nodeJS app server-side that receives files. The user sends a file from the client and I want to make several operations, one of them being moving the file to the final destination. I used to use file.mv, but I need to make my functions…
djcaesar9114
  • 1,880
  • 1
  • 21
  • 41
0
votes
0 answers

Merging data:application/octet-stream;base64 video chunks into a file

I have an upload button on my page which user can click to upload a video. If video is large, Javascript's File Reader can't handle it. So I've implemented a function that slices uploaded video into chunks with…
0
votes
2 answers

I am trying to take two different files and sum the data

So I wrote this fs function to read files data from a file: const fs = require("fs"); const read = function (file) { fs.readFile(file, "utf8", (err, data) => { if (err !== null) { throw err; } console.log(data); …
aNewmoon
  • 3
  • 3
0
votes
1 answer

Can't resolve 'fs' in electron-react-boilerplate app

colleagues, I have encountered with 2 errors. Tried many solutions found in stackoverflow and www but nothing helped. I would appreciate much if you provide any suggestions. ERROR in ./src/component/FileReaderComponent.tsx 8:11-24 Module not found:…
baton
  • 21
  • 4
0
votes
2 answers

read all the file and store in object format in node js / javascript

I wrote a code which help me to read all the folder file and make me store them in array format so my code looks like this readAll.js module.exports = readAllFile = () => { const arr = []; fs.readdir(path.join("./admin/requiredFiles"), (err,…
0
votes
1 answer

How to sort objects into file based on date?

Title says all, i'm trying to put objects into files based on their dates. For exmaple, I have files named "May 23","May 24","May 25" ect ect. My objects (in simplest terms) looks like this: {id: 1, mintDate: May 23},{id: 1, mintDate: May 24},{id:…
netsocket
  • 117
  • 1
  • 10
0
votes
0 answers

convert base64 string to base64 url in node.js

I was wonder how to convert a base64 string to a base 64 url that you could use in the browser for my project. I've already tried using base64.toString('base64url'), but that didn't work. Below is some example code. const fs=require("fs") let…
codingtuba
  • 366
  • 2
  • 13
0
votes
0 answers

How can you write to an Object File from JavaScript?

I have a string with hexadecimal code for an object file I have generated in a program previously in my JavaScript file. How can I create an object file with this code, preferably with the fs module? So far, I've tried using the hex and binary…
0
votes
0 answers

How to wait for the callback to be finished with fs.readdir?

I'm using fs.readdir callback function to do stuff in a path file but i want to wait for the callback to be finished to continue on with the rest of my code. const get = async(path_files) => { fs.readdir(path_files, function(err, files) { …
RouckyKM
  • 85
  • 1
  • 8
0
votes
0 answers

React - Module not found: Error: Can't resolve 'fs' in '/Users/andreadavide/Documents/testAssoDeploy/node_modules/basic-ftp/dist'

I'm struggling with this error and I've already tried many ways but unfortunately I'm not able to solve the problem. When I install any kind of FTP npm I receive this error. I've installed "basic-ftp" this time. Module not found: Error: Can't…
0
votes
2 answers

Write an array into an file fs

I want to create a .txt file which contains my array, using fs. My array looks like this: const array = [1111, 2222, 33333] The code below allows me to write in the file and seperate each entry with a comma but I cant get them on a new line.…
N0rmal
  • 47
  • 1
  • 7
0
votes
1 answer

How to read and write to local text file from a localhost server (preferably using Node's fs module)

I'd like to find an easy way of reading and writing files (stored locally) from my program running on a localhost server. If I use const fs = require(fs) it can't find the Node module from the server. This makes sense. Is there any way of accessing…
0
votes
1 answer

How do I mock an fs.writeFile call with a promise using jest?

After trying many ways to do this, I've hit a brick wall. With the code I have now, once the fs.writeFile is dummied, the software throws the following error: Error: ENOENT: no such file or directory (followed by the path and file). A simple…
jenkinz
  • 139
  • 10