1const fs = require('fs');
2
3// File destination.txt will be created or overwritten by default.
4fs.copyFile('source.txt', 'destination.txt', (err) => {
5 if (err) throw err;
6 console.log('source.txt was copied to destination.txt');
7});
8
1'use strict';
2
3import fs from 'fs';
4
5let fileContent = 'Anything what you want';
6let message = fs.writeFileSync('message.txt', fileContent);
7
8function copyContent(fileName: string, dest: string): boolean {
9 try {
10 fs.copyFileSync(fileName, dest);
11 console.log(dest);
12 return true;
13 } catch (err) {
14 return false;
15 }
16}
17
18console.log(copyContent('message.txt', 'destination.txt'));