0

I'm trying to create a folder and a file inside that folder from my Remix js app. So after certain action, I did the following but this doesn't work from my Remix app.

But it works as expected when I create a sample.js file outside of the remix project and run the sample.js file.

How can I fix this issue?

const fs = require('fs');
const path = require('path');

// Define the folder directory. 
const newFolderPath = path.join("./", 'newFolder');

// Define the file directory. 
const newFilePath = path.join(newFolderPath, 'newFile.txt');


// Function to create new folder and file
async function createFolderAndFile() {
  try {
      // Create a new folder
      await fs.promises.mkdir(newFolderPath);

      // Create a new file within the folder
      await fs.promises.writeFile(newFilePath, 'Hello, World!', 'utf8');

      console.log('New folder and file created successfully.');
  } catch (error) {
      console.error('Error creating folder and file:', error);
  }
}

createFolderAndFile();

Thanks!

2
  • Something about file permissions? Are you able to get any error messages or does it fail silently? Commented Mar 12, 2024 at 10:25
  • No error message, it just fails silently. Commented Mar 12, 2024 at 10:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.