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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
'env': {
'commonjs': true,
'es2022': true,
'es2021': true,
'node': true
},
'extends': 'eslint:recommended',
Expand Down
17 changes: 17 additions & 0 deletions 01-read-file/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fs = require('fs');
const path = require('path');

const readFile = () => {
const filePath = path.join(__dirname, './text.txt');
const fileStream = fs.createReadStream(filePath, { encoding: 'utf8' });

logChunks(fileStream);
};

async function logChunks(readable) {
for await (const chunk of readable) {
console.log(chunk);
}
}

readFile();
25 changes: 25 additions & 0 deletions 02-write-file/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require('fs');
const path = require('path');

const writeFile = () => {
const filePath = path.join(__dirname, './text.txt');

const file = fs.createWriteStream(filePath, { flags: 'a' });

process.stdin.on('data', (data) => {
if (data.toString().trim() === 'exit') {
console.log('Bye...');
process.exit();
}
file.write(data);
});

process.on('SIGINT', () => {
console.log('\n');
console.log('Bye...');
process.exit();
});
};

writeFile();