Questions tagged [node.js-fs]
203 questions
47
votes
5 answers
fs/promises API in TypeScript is not compiling correctly in JavaScript
I was recently working with TypeScript and the fs/promises API and got this error when the TypeScript code was compiled and run. I got this error saying:
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module…

Rahul
- 1,091
- 1
- 8
- 12
43
votes
3 answers
How can I get the application base path from a module in Node.js?
I'm building a web application in Node.js, and I'm implementing my API routes in separate modules. In one of my routes I'm doing some file manipulation and I need to know the base app path. If I use __dirname, it gives me the directory that houses…

Clint Powell
- 2,368
- 2
- 16
- 19
9
votes
2 answers
How can I get type from fs.Dirent?
I can call
fs.readdirSync("C:\\", { withFileTypes: true })
and get array of fs.Dirent, but they look like
> fs.readdirSync("C:\\", { withFileTypes: true })[32]
Dirent { name: 'Windows', [Symbol(type)]: 2 }
> fs.readdirSync("C:\\", { withFileTypes:…

Qwertiy
- 19,681
- 15
- 61
- 128
6
votes
0 answers
how to use file system (fs) in angular 2
In my angular 2 application, need to use file system for uploading large files to Amazon S3 server. But, I have problem in importing file system in my application. Please help to implement file system in my application.
My component.ts file
import…

Manush
- 1,852
- 7
- 26
- 39
4
votes
1 answer
How to mock file system with memfs in NodeJS
I want to test the following function with the memfs package
import fs from 'fs-extra'
import path from 'path'
async function ensureParent(filepath: string) {
const absolutePath = path.resolve(filepath)
const parentDir =…

DavNej
- 176
- 3
- 10
3
votes
1 answer
Node.js - How to write different texts to a file depending on if it exists or not, without race conditions
Let's say I want to have a file like this
Intro-Text on creation
--------------------------
date - event-text
date - event-text
date - event-text
The first 3 lines are written when the first event occurs.
On every other event only one line is…

andymel
- 4,538
- 2
- 23
- 35
3
votes
3 answers
NUXT: Cannot find module node:fs
Getting the following error while doing yarn generate in production in a Kubernetes container. It is working fine on local. And it was also working fine on production till last week.
Error: Cannot find module 'node:fs'
Require stack:
-…

Syed Ahmed
- 112
- 1
- 7
2
votes
1 answer
How to use flags to append data to file in Node.js?
I have a JavaScript function that writes data to a .json file. Right now, whenever I run the function is deletes or overwrites the existing content on the .json file.
I want to change this so that whenever I run the function new data is appended to…

MeltingDog
- 14,310
- 43
- 165
- 295
2
votes
0 answers
Error: ENOTEMPTY: directory not empty, rmdir when I use fs.rmSync on a folder with nested folders
I have a react + node website in which I have the following route to delete a folder called cache and remake it. Basically it should "clear cache".
const deleteCache = async (req, res) => {
fs.rmSync('./cache', {recursive: true, force : true},…

Ruo
- 77
- 7
2
votes
0 answers
Why do @fs occur in the image path I import?
I create a script named "FileUtil.jsx" to import a bunch of images and export them to another component.
import Oolong from '../assests/img/Oolong.png'
import ChaiTea from '../assests/img/ChaiTea.png'
import CharcoalRoastedOolong from…

Li Jie Su
- 21
- 3
2
votes
1 answer
Value undefined after being resolved from Promise
I think the problem here might be wrong awaits, or the fact that I have a wrapped up callback inside the promise and I'm trying to resolve the promise inside that callback. Not sure how to fix this. Any help is much appreciated!
async function…

nickcoding2
- 142
- 1
- 8
- 34
2
votes
1 answer
Module not found: Can't resolve 'fs' (when importing google from googleapis)
I get the Module not found: Can't resolve 'fs' error when I try to import from googleapis.
//submitData.js
import { google } from "googleapis";
import keys from "../secrets.json";
export default async function submitData(data) {
try {
//…
user21369506
2
votes
1 answer
Including .hbs handlebars file in Typescript transpile
I've been trying to use handlebars in my Typescript node.js project by importing it through the readFileSync fs method, however when the project is transpiled into Javascript the .hbs file does not appear in the dist folder and the code can not…

Cyber_Pedro
- 60
- 7
2
votes
2 answers
amazon s3 - uploading empty image to bucket when using createWriteStream
When using createWriteStream, without any error it uploads image to bucket but empty(size-0B).
const uploadImage = async (filePath, fileId) => {
const fileStream = fs.createWriteStream(filePath);
const uploadParams = {
Bucket: bucket,
…

dthakurani
- 21
- 1
2
votes
1 answer
Use url link instead of path to file in Node JS
I have a requirement to process a file in node to extract some text from that file, my issue is since i am new to node, i don't understand how to pass the path to the file. I am using cloud Function for Firebase so there is no server, hence no…

Scorpion Edge
- 41
- 5