'Finally' for forEach - Callback After All forEach are done running

In Promise there is a finally() - runs after all chains, error are done. Anything similar in Array.forEach() ? May be needed when you want to do something at the end of the async stuff that happens on each of the array elements - when all are done. This can be easily done by following: ref Using a basic counter function callback () { console.log('all done'); } var itemsProcessed = 0; [1, 2, 3]....

May 10, 2022 · 1 min · Anant

Node: User Input from Terminal

This article has a good summary The basic: const readline = require('readline').createInterface({ input: process.stdin, output: process.stdout }); readline.question('Who are you?', name => { console.log(`Hey there ${name}!`); readline.close(); }); Using prompt-sync package After npm install prompt-sync const prompt = require('prompt-sync')(); const name = prompt('What is your name?'); console.log(`Hey there ${name}`); Working with Numbers All user input will be read as a String, so in order to treat user input as numbers, you’ll need to convert the input:...

May 10, 2022 · 1 min · Anant

Node: Change the color of your console.log

This SO shows a neat way to customize color of your console.log text

May 10, 2022 · 1 min · Anant

Node: fs common uses

Official Doc: File System API const fs = require('fs'); Append to a file (if file doesnt exist, create it) Useful when need to log to a file. fs.appendFile('message.txt', 'data to append', function (err) { if (err) throw err; console.log('Saved!'); }); Write a file const fs = require('fs'); fs.writeFile("/tmp/test", "Hey there!", function(err) { if(err) { return console.log(err); } console.log("The file was saved!"); }); // Or fs.writeFileSync('/tmp/test-sync', 'Hey there!'); Read a file one line at a time Since Node....

May 10, 2022 · 2 min · Anant

Day4 #100DaysOfCode

Build $ npm run build generates static pages. Terminal: Page Size First Load JS ┌ ● / 724 B 78.2 kB ├ └ css/233a1356c16eb650.css 416 B ├ /_app 0 B 77.5 kB ├ ○ /[noteId] 484 B 78 kB ├ └ css/f0a2be9a550dc29f.css 79 B ├ ○ /404 193 B 77.7 kB └ ○ /new-note 749 B 78.2 kB └ css/29ba8ee8d48d1f49.css 359 B + First Load JS shared by all 77.5 kB ├ chunks/framework-1f10003e17636e37....

May 10, 2022 · 4 min · Anant