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
2 answers

FS rename file - Error: ENOENT: no such file or directory, rename '24.png' -> '1.png'

I am trying to write a little script that will rewrite the file names of the images in my folder. Where am I going wrong? I am getting this error: FS rename file - Error: ENOENT: no such file or directory, rename '24.png' -> '1.png' const fs =…
BennKingy
  • 1,265
  • 1
  • 18
  • 43
0
votes
2 answers

How do I get only the elements from an array that end with "x" or "y"?

I have a function that recursively searches a directory for files and returns them as an array. I only want files that end with ".js" or ".ts". For that, I'm trying to use Array.filter(). However, it looks as if this would not work, since only files…
user17817674
0
votes
2 answers

How can I convert from a Javascript Buffer to a String only containing 0 and 1

So I currently am trying to implement the huffman alg and it works fine for decoding and encoding. However, I store the encoded data as follows. The result of the encoding function is a list containing many strings made up of 0 and 1 and all are…
Royal Foxy
  • 49
  • 4
0
votes
2 answers

How can I delete a file after I have sent it by email?

Right now Im working with Node JS using PDFKit to generate PDF files, I want to delete the file after sent it by email using Nodemailer, here is my code: reportcontroller.sendrecordsemail = async (req,res)=>{ try{ const doc = new PDF({ …
0
votes
0 answers

NodeJS fs.writeFile simply will not write the file to the correct directory

I have been working on trying to fix this for two hours. I am using macOS. I have copied my professor's code to the T. The path is correct. fs.writeFile just... won't write the file into the correct directory. const fsPromises =…
0
votes
1 answer

Is there a way for a program to write over itself while open in memory?

ERROR: The process cannot access the file because it is being used by another process. (os error 32) I'm creating a program in rust and I'm currently working on an 'auto updater'. I'm trying to have the program write over itself if an update was…
0
votes
1 answer

how to edit value of the .JSON object

I'm trying to create some simple statistics in the .JSON file, I would like to count each command that was issued, but I'm unable to save increment value in the .JSON file. .JSON { "stats": { "value": 0, "points": 0, …
RasmonT
  • 391
  • 2
  • 13
0
votes
1 answer

Accessing Functions, Variables and others from one script and being able to use them in another

If there is a java script file with some functions and some variables and another java script file that wants to access them or use them in what way can it do that? I have a js file with something like lets say const info = { get: function(){ …
DcraftBg
  • 27
  • 5
0
votes
0 answers

Writing to text file deletes the whole content inside a text file Node.js

So I am trying to write this simple program where it just writes some text in a text file whenever I run it. And when I run it, it does write to the text file how it is supposed to, but it deletes the other content inside the text file. here's my…
user17151862
0
votes
1 answer

Node JS : Express JS : Formidable : Nodemailer - How can i upload a html template on contact form and send it using Nodemailer?

I have a contact form and i want to upload a html template using the input file and send it with Nodemailer. I have used formidable to get a temporary path but im not able to pass this parameter to the HTML tag of sendMail. How can i archive this…
Astrit Shuli
  • 619
  • 4
  • 20
0
votes
1 answer

Node/Typescript: How to close a writestream in the process 'exit' event - red/blue function problem / async infection

In my current FOSS Discord bot project I have this log.ts file which handles the logging for the bot. It creates multiple fs.WriteStream objects, which write to each log file. There is a section in the code when await log('CLOSE_STREAMS') is called…
0xLogN
  • 3,289
  • 1
  • 14
  • 35
0
votes
1 answer

Node JS File system

I'm learning node.js and currently on how to copy file system, import * as fs from 'fs'; import * as fs from 'fs/promises'; fs.copyFileSync("file1.txt", "file2.txt"); Using the above in VS code, I get prompts like: remove import from fs for first…
Eniola
  • 3
  • 1
0
votes
1 answer

Node.js Why such a sequence of output to the console?

Why is there such a sequence in the console: enter image description here const crypto = require('crypto'); const https = require('https'); const fs = require('fs'); const startDate = Date.now(); const invokeHttpRequest = () => { …
YouJeen
  • 1
  • 1
0
votes
3 answers

how do I ensure two asynchronous operations add to a file sequentially?

I have this code: const fs = require("fs"); const saveFile = (fileName, data) => { return new Promise((resolve) => { fs.writeFile(fileName, data, (err) => { resolve(true); }); }); }; const readFile = (fileName) => { return new…
0
votes
0 answers

How to write to xml file with hebrew content

I have an XML file with number of Records with Hebrew content and after I read It I want to save some of the Records that satisfied special condition to new XML file, but when I wrote to this new file, the Hebrew content convert to Gibberish like…
Yakir
  • 1
  • 2
1 2 3
99
100