What If I Say That You Have Been Learning Node The Wrong Way?

I have been learning Node.js for a while now. The following post acts as a short Node.js knowledge challenge. So if you truly answer all of these questions, then your knowledge of Node.js is beyond great.

The only reason why I think this post will take you by surprise is that many of us have been mostly learning Node the wrong way. No kidding! I am sure you have gone through several tutorials, books, and courses regarding the Node ecosystem but definitely not the Node runtime itself. Most of them focus on teaching what can be done with all the packages available for you while working with Node, like Express and Socket.IO, rather than teaching the capabilities of the Node runtime itself.

Being a raw and flexible platform, Node doesn’t provide complete solutions but rather provides a rich runtime that enables you to implement solutions of your own. Libraries like Express.js and Socket.IO are more of complete solutions, so it makes more sense to teach those libraries, so you can enable learners to use these complete solutions. I personally believe that having a solid understanding of the Node.js runtime is the best thing you can do before using those complete looking solutions.

Let’s begin with the challenge!
1. What is the relationship between Node.js and V8? Can Node work without V8?
2. Can we require local files without using relative paths?
3. What is the Event Loop? Is it part of V8?
4. What is the Call Stack? Is it part of V8?
5. What is the difference between setImmediate and process.nextTick?
6. How can we do one final operation before a Node process exits? Can that operation be done asynchronously?
7. What are some of the built-in-dot commands that you can use in Node’s REPL?
8. Besides V8 and libuv, what other external dependencies does Node have?
9. When working with streams, when do you use the pipe function and when do you use events? Can those two methods be combined?
10. What’s the difference between the Paused and the Flowing modes of readable streams?

Nodejs Development

Easy- peasy! Learning Node.js can be challenging. Further, I would like to mention a few guidelines that can provide you help to a great extent.

Learn the good parts of JavaScript (including its modern syntax)

Node is a set of libraries on top of a VM engine that compiles JavaScript. And maybe that’s the reason why it goes without the saying that the important skills for JavaScript itself is a subset of the important skills for Node. You should start with JavaScript itself.

Are you well versed with functions, scopes, binding, this keyword, new keyword, closures, classes module patterns, prototypes, callbacks, and promises? Do you know methods that can be used on Numbers, Strings, Arrays, Sets, Objects, and Maps? Getting yourself comfortable with the items on this list will make learning the Node API much easier.

Understand the non-blocking nature of Node

Callbacks and promises (and generators/async patterns) are especially important for Node. Although, you can compare the non-blocking nature of lines of code in a Node program to the way you order a Starbucks coffee (in the store, not the drive-thru):
• Simply place your order- Give Node some instructions to execute (a function)
• Customize your order, no whipped cream, for example, | Give the function some arguments: ({whippedCream: false})
• Give the Starbucks worker your name with the order | Give Node a callback with your function: ({whippedCream: false}, callback)
• Step aside and the Starbucks worker will take orders from people who were after you in line | Node will take instructions from lines after yours.
• When your order is ready, the Starbucks worker will call your name and give you your order | When your function is computed and Node.js has a ready result for you, it’ll call your callback with that result: callback(result)

Lastly, don’t forget to learn how a Node process never sleeps and will exit when there is nothing left to do. A Node process can be idle but it never sleeps. It keeps track of all the callbacks that are pending and if there is nothing left to execute it will simply exit. So that’s all for now! For more information and updates visit a Node development company.

Categorized as Node.js