bhaiya i did not understand how the flow of logic will u pleae explain how the call cal each other
Bhaiya i did not understand how the flow of logic will u pleae explain how the call cal each other
@Aditya-Kushwaha-914550392281281 can you please specify in which part are you having problem with so that I can clear your doubt.
bhaiya at time stamp 1.08 from there how calls are execute
my bad its 1hr 08 minutes from that time bhaiya explaining some logic will u please explain
@Aditya-Kushwaha-914550392281281 are you talking about the lib1 and lib2 require flow, or the working, non working flow part?
@Aditya-Kushwaha-914550392281281 let me explain the lib1 and lib2 part
const lib1 = require('./lib1.js')
const lib2 = require('./lib2.js')
console.log(lib1)
console.log(lib2)
console.log(lib1.lib2)
console.log(lib2.lib1)
as you already know js is an interpreted language, i.e. it goes line by line so when first line gets interpreted lib1.js is required/imported and in lib1.js we are requiring lib2.js and again in lib2.js we are requiring lib1.js. As, you can see it is a deadlock situation or infinite importing process, so to deal with it what nodejs developers have done is that, when a file that is partially imported is imported again it returns null.
- first main file require lib1 and
- lib1 imports lib2, everything works fine till here
- then in lib2 when we require lib1 which is already required in main (as per node internals, it returns null object)
- now lib2 returns
{ b: 20, lib1: {} } - then lib1 returns
{ a: 10, lib2: { b: 20, lib1: {} }back to the main
Then second line of main gets executed i.e.
const lib2 = require('./lib2.js')
- again main requires lib2
- and gets
{ b: 20, lib1: {} }
I hope this clears your doubt regarding the flow.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.