Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions 01-read-file/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require('fs');

fs.readFile('./text.txt', 'utf8', (err, data) => {
if (err) {
console.error(err);
} else {
console.log(data);
}
});
18 changes: 18 additions & 0 deletions 02-write-file/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require('fs');
const readline = require('readline');

console.log('Привет! Введи текст для записи в файл:');

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

rl.on('line', (text) => {
fs.writeFile('text.txt', text, (err) => {
if (err) throw err;

console.log(`Текст "${text}" успешно записан в файл text.txt`);
rl.close();
});
});
13 changes: 13 additions & 0 deletions 03-files-in-folder/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const fs = require('fs');

const folderPath = './03-files-in-folder/secret-folder';

fs.readdir(folderPath, (err, files) => {
if (err) {
console.error('Error reading directory:', err);
return;
}

console.log(`Files in directory ${folderPath}:`);
files.forEach(file => console.log(file));
});
22 changes: 22 additions & 0 deletions 04-copy-directory/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
const fs = require('fs');

function copyDir(sourceDir, targetDir) {
if (!fs.existsSync(sourceDir)) {
throw new Error(`Source directory "${sourceDir}" does not exist`);
}
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir);
}
const files = fs.readdirSync(sourceDir);
files.forEach((file) => {
const sourcePath = `${sourceDir}/${file}`;
const targetPath = `${targetDir}/${file}`;
const stat = fs.statSync(sourcePath);
if (stat.isDirectory()) {
copyDir(sourcePath, targetPath);
} else {
fs.copyFileSync(sourcePath, targetPath);
}
});
}

copyDir('./files', './files-copy');
21 changes: 21 additions & 0 deletions 05-merge-styles/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const fs = require('fs');
const concat = require('concat');

const stylesFolderPath = './styles';
const outputFilePath = './project-dist/bundle.css';

fs.readdir(stylesFolderPath, (err, files) => {
if (err) {
throw err;
}

const fileContents = files.map((fileName) => {
return fs.readFileSync(`${stylesFolderPath}/${fileName}`, 'utf-8');
});

const concatenatedContents = concat(fileContents);

fs.writeFileSync(outputFilePath, concatenatedContents, 'utf-8');

console.log('Styles merged successfully');
});