Glad to have you back for this week's IBM i Pulse! Each week we will be taking a deeper look at this week's IBM i news. This week we are looking at all things Node.js! But First...
Here is a really interesting article on the history of IBM... it is always fun to look at how things started!
by Rahul Mhatre
- Immediately Invoked Function Expressions - an IIFE is a function that is executed as soon as you create it.
- Closures - an inner function that has access to an outer function's scope, even if the outer function returned control.
- Prototypes - this is used to attach properties and methods.
- Private Properties Using Closures - define private properties using underscore prefixes.
- The Module Pattern - allows developers to create public and private access levels.
- Hoisting - moving variables and function declarations to the top of their scope before code execution.
- Currying - making functions more flexible.
- Memoization - an optimization technique that will speed up function execution.
- Method Overloading - allowing multiple methods to have the same name, but different arguments.
What You Should Know to Really Understand the Node.js Event Loop
by Daniel Khan
Everything that happens in Node is based on an event, which makes it an event-based platform. The event loop is a mechanism created by a library (libuv) that takes a transaction through a series of callbacks. This is all done independently from any developers. This event loop can be a very misunderstood concept of the Node platform to many developers and in this article Daniel aims to help you better understand the Event Loop. He goes into many details, but we will briefly focus on the misconceptions of the Node.js Event Loop.
Misconception 1: The Event Loop Runs in a Separate Thread in the User Code
Misconception 2: Everything That is Asynchronous is Handled by a Thread Pool
Libuv will be default create thread pool with 4 threads to help offload asynchronous work. It is not like working with a filesystem where the operations doing outbound HTTP requests to databaseses are ALWAYS loaded off to a thread pool. Whenever it can, libuv will avoid the usage of thread pools by using asynchronous interfaces.
Misconception 3: The Event Loop is Something Like a Stack or Queue
Nope! The event loop will not continuously traverse a FIFO of asynchronous tasks and execute that callback when the task is completed. The reality is there are queue-like structures, the event loop does not run through and process a stack. It is actually a set of phases that have specific tasks that are processed in a round-robin type manner.
For more on Node.js Event Loops, check out the full article below.
Checklist: Node.js Production Best Practices
by Yoni Goldberg
Curious as to how to best use Node.js? New to the framework and are unsure and need some guidance? This is a collection of tips to help those of you who are running Node.js already. These tips have been gathered by some of the top influencers in the Node world, make sure to read the full article to read the "GIST Popups" each tip has. Here are 10 of Yoni's best practices:
- Monitoring - Find any issues before your customers do!
- Use Smart Logging - this will increase transparency if you start planning how you will set up your logs from the start.
- Delegate to a Reverse Proxy - Node has difficulty doing intensive CPU tasks... delegate these if you can.
- Guard Process Uptime - If you run dozens of instances without the right cluster management, you risk running into devop hell!
- Error Management Best Practices - Create and understand how your business handles errors and stick to that system across the entire company.
- Utilize All CPU Cores - You must replicate the Node process on all CPU's because Node at its core runs over a single CPU.
- Create a Maintenance Endpoint - this will prevent you from performing many "diagnostic deploys" and shipping code to production only to extract information for diagnostics.
- Discover Downtime and Errors - Use of an APM product can help you discover these time consuming issues.
- Make Code Production Ready - If you have in your mind from day one what your code needs to look like to be production ready, you will have a clear path to get there.
- Security - Node has unique security challenges, make sure to take every precaution you can to keep your code secure.
November 15th-17th Profound Logic will be hosting our 2nd annual PLUS Seminar for their customers. Get the most value from your Profound Logic investment and assure your modernization success. Register here today!
One of our focuses for 2017 is the continued adoption of Node.js in IBM i shops. Click here to read our white paper on Why Node.js Is The Solution Your Company Needs.
Also, Profound.js 2.0 has been released! See how Profound.js 2.0 can help modernize your IBM i today!
And there, you're all caught up! Sounds like we have an interesting 2017!