I am writing this code and even though I added fetchDir from fs it is still not taking fetchDir as a function and is showing me an error…
the code is
const http = require('http');
const express = require('express');
const {Server: SocketServer } = require('socket.io');
const cors = require("cors");
const { Socket } = require('socket.io');
const { copyS3Folder, fetchS3Folder, saveToS3 } = require('./awsStart.js');
const { stringify } = require('querystring');
const {fetchDir, fetchFileContent, saveFile} = require('fs');
const path = require("path");
const fs = require('fs/promises');
const app = express()
app.use(cors());
const server = http.createServer(app)
const io = new SocketServer(server, {
cors:"*"
})
io.on("connection", (socket) => {
socket.on("fetchStartUpProjects", async (data) => {
console.log("Fetch Function Recieved",data)
await fetchS3Folder(`code/${data}`, path.join(__dirname, `../tmp/${data}`));
socket.emit("loaded", {
rootContent: await fetchDir(path.join(__dirname, `../tmp/${data}`), "")
}
);
console.log("success", fetchDir(path.join(__dirname, `../tmp/${data}`), "") )
});
})
server.listen(3000, () => console.log("Server is Running"));
and the error that I am receiving in the cmd is
console.log("success", fetchDir(path.join(__dirname, `../tmp/${data}`), "") )
^
TypeError: fetchDir is not a function
I dont why it is happening.. also keep in mind that I am a beginner
I tried to change fs and the way I am importing it but the error is that same