Day6 #100DaysOfCode

Day 6 Using mongoDB in the nextjs app. So far covered: getStaticProps, and getStaticPaths and getServerSideProps They allow us to fetch data for pre-rendering those pages, So that we pre-render the pages with the data, instead of without the data they might need. Upto this point, we’re only working with dummy data though (not actually fetching from anywhere) - it is actually hard-coded data We do have this Add New Meetup page here, which would allow users to enter data for a new meetup....

May 11, 2022 · 6 min · Anant

Day5 #100DaysOfCode

Day 5 Key learnings: React hooks like useRouter cant be used in GSP (getStaticProps) - it can only be used in React function component. So can’t use useRouter to get the slug (like ID of note/post). But we dont need it - we have context param in GSP. In GSP the context will not hold req and res - it has params: the params object has key = the thing between [] in the filename....

May 10, 2022 · 4 min · Anant

'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