0

In nodejs , I want to copy multiple files to a single file and want to append one file into another file, What is the function name?

this.fs.copy(
            this.templatePath('testing.json' + 'testing2.json'),
            this.destinationPath('public/index.html')
          )

like this, I want to copy from multiple location to single file

this.fs.appendFile('public/index.html', 'hdjkfhsdjkfh');

1 Answers1

0

There is no single function to fit your specific need in the built-in modules.

I suggest you use readFileSync in a loop first, concatenate them and use writeFileSync to write to your destination.

The append task could be done similarly with readDileSync then use appendFileSync

If you want to use async operations, I suggest you try the fs.promise namespace which simplifies the async with loop scenario.

If what you are doing is merging assets for a frontend page, I suggest you look into tools like webpack to automate this process.

obfish
  • 673
  • 4
  • 17