After the problems I was having with understanding the structure of Node and its frameworks (https, express etc) I picked up the The Node Beginner Book by Manuel Kiessling and read it over the weekend.
So we went about building a basic HTTPS server in a file called server.js.
I won’t go through the entire tutorial here, but the next step is important, introducing call back functions,
Here’s the explanation with it,
“What we are doing here is, we pass the function say as the first parameter to the execute function. Not the return value of say, but say itself! Thus, say becomes the local variable someFunction within exe- cute, and execute can call the function in this variable by issuing someFunction() (adding brackets).
Of course, because say takes one parameter, execute can pass such a parameter when calling someFunction.
We can, as we just did, pass a function as a parameter to another function by its name. But we don’t have to take this indirection of first defining, then passing it - we can define and pass a function as a parameter to another function in-place.”
“We define the function we want to pass to execute right there at the place where execute expects its first parameter. This way, we don’t even need to give the function a name, which is why this is called an anonymous function.”
My life got pretty exciting after that. I’m not even sure if I’m being sarcastic, lol, but one thing’s for sure I am currently living in Callback Hell. Going through the book hasn’t been the smoothest undertaking, but I feel I’m getting somewhere. When I think about it in the context of my finals, I panic I’m not!