Questions tagged [node.js-fs]

203 questions
0
votes
0 answers

How to write binary data to file and keep the file open in NodeJs?

I need to write a sequence of boolean and float values to a file in binary using Javascript. I would like to keep the file open and then just do a sequence of writes. Here is the pseudocode of what I would like to accomplish file =…
0
votes
0 answers

TelegramError Error: 400: Bad Request: invalid file HTTP URL specified: Wrong port number specified in the URL

This unacceptable error occurs when using ytdl-core and telegraf javascript, all because of these two lines of code: let video =…
0
votes
1 answer

Is the a way to cancel/not list directories/files which can't be read anyways because of lacking permission by fs.readdirSync?

A way to filter out those directories which need administration permission. fs.readdirSync(currentPath, { withFileTypes: true }).forEach(element => { .... }) Still shows all directories. Even those that need admin permission to be read/written…
Bugger
  • 1
0
votes
1 answer

Rehydrate redux state when Tauri app open

I am small working on a small Tauri app. For the state management. am using Redux Toolkit. Until now i have been using localStorage to persist my data but i would like to change to something that allows me to save more data, like a JSON file on the…
Boguz
  • 1,600
  • 1
  • 12
  • 25
0
votes
2 answers

How do properly chain these .then statements so they resolve in the correct order?

The assignment I'm working on is to design a Node.js program that presents the user with command line prompts and writes a well-organized README markdown file with the input. The prompts are created with the Inquirer NPM. The code starts with the…
Sam Tomaka
  • 23
  • 5
0
votes
1 answer

having problems with `fs.writeFile` it doesn't create files

I'm trying to start a script that itself creates a model file in json using fs.writeFile. The problem is when I run the script using node file.js. It is supposed to create a new file face-expression-model.json in directory /models but it doesn't…
ImadAris
  • 15
  • 5
0
votes
2 answers

Node/express - cancel multer photo upload if other fields validation fails

I have multer as middleware before editing user function. The thing is that multer uploads photo no matter what, so I am wondering if there is a way to somehow cancel upload if e.g. email is invalid. I tried to delete uploaded image through function…
0
votes
0 answers

Create a file then add an arbitrary text using fs functions in node js

Is there a reason why this code doesn't work? additionally using node file.js responds MODULE_NOT_FOUND. const fs = require('fs'); // Create the "text.txt" file with the content "hello world" fs.writeFileSync('text.txt', 'hello world'); // Add…
0
votes
1 answer

Unexpected keyword or identifier.ts(1434)

I have the following code that tries to read a file from the local machine and upload it to the AWS s3 cloud service: import AWS from 'aws-sdk'; import fs, { ReadStream } from "fs"; import path from "path"; class Uploads { static const…
0
votes
1 answer

Core Node.js module "fs" Not Found when @fastify/static deployed on render.com

It is my understanding that the core modules, like "fs" are part of the node.js build, and no special configuration is needed to make them available for importing, so I'm at a loss as to how "fs" could be missing when running on render.com. I have…
kelly
  • 13
  • 3
0
votes
0 answers

Property 'mimetype' does not exist on type 'ReadStream'.ts(2339)

I was trying to convert a code that was written using fs.readFile() to a code uses fs.createReadStream() like below: const filePath = "/home/a/bars/img1.png"; const uploadParams: { Bucket: string; Key: string; Body: string | ReadStream;…
best_of_man
  • 643
  • 2
  • 15
0
votes
1 answer

Type 'ReadStream' is not assignable to type 'string'.ts(2322)

I am trying to run the following code: const uploadParams = {Bucket: bucketName, Key: '', Body: ''}; const file = '/home/a/bars/img1.png'; const fileStream = fs.createReadStream(file); fileStream.on('error', function(err) { console.log('File…
best_of_man
  • 643
  • 2
  • 15
0
votes
0 answers

Winston logger - save logs in reverse order or fs module read log files backwards

I am working on a logger for my application. I need to order my logs from the newest to the oldest. However, by default Winston saves my logs from top down (oldest on top, new log lines on last line). Finding a solution to get the lines saved in…
Monika
  • 87
  • 1
  • 7
0
votes
1 answer

fs.statSync() isn't giving actual BirthTime of the file - NodeJs

I am using fs (Node Module) to manage files. I am getting the file's created time (BirthTime). It is working absolutely fine when I run this app on my local machine. But when I try to implement it on EFS using NodeJs Lambda function then it gives…
Rehan CH
  • 109
  • 1
  • 11
0
votes
1 answer

createWriteStream instance shadowing another instance in nodeJS

My aim is to do something like that : function writer1(data,file){ const w = fs.createWriteStream(file,{flags:'w'}) for(let i = 0; i< data.length; i++){ w.write(data[i]) } w.end() } function writer2(data,file, *some-stuff*){ …
AVALFINN
  • 23
  • 3