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
31 changes: 31 additions & 0 deletions 1-node-farm/starter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs');

// Sync way, blocking
const textIn = fs.readFileSync('./txt/input.txt', 'utf-8', (err, data)=>{
console.log(data);
});

console.log(textIn)

const textOut = `this is what we know about the avacado: ${textIn}.\n created on ${Date.now()}`;

fs.writeFileSync('./txt/output.txt', textOut);
console.log('File Written!');


// Async way, non-blocking


fs.readFile('./txt/start.txt', 'utf-8', (err, data1)=>{
fs.readFile(`./txt/${data1}.txt`, 'utf-8', (err, data2)=>{
console.log(data2);
fs.readFile(`./txt/append.txt`, 'utf-8', (err, data3)=>{
console.log(data3);
fs.writeFile('./txt/final.txt',`${data2}\n${data3}`, 'utf-8', err=>{
console.log('your file has been written !');
});
});
});
});

console.log(`Reading file....`)
3 changes: 2 additions & 1 deletion 1-node-farm/starter/txt/final.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
The avocado 🥑 is also used as the base for the Mexican dip known as guacamole, as well as a spread on corn tortillas or toast, served with spices. APPENDIX: Generally, avocados 🥑 are served raw, but some cultivars can be cooked for a short time without becoming bitter.
The avocado 🥑 is also used as the base for the Mexican dip known as guacamole, as well as a spread on corn tortillas or toast, served with spices.
APPENDIX: Generally, avocados 🥑 are served raw, but some cultivars can be cooked for a short time without becoming bitter.
2 changes: 2 additions & 0 deletions 1-node-farm/starter/txt/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
this is what we know about the avacado: The avocado 🥑 is popular in vegetarian cuisine as a substitute for meats in sandwiches and salads because of its high fat content 😄.
created on 1628979969797