Friday, 8 March, 2019 UTC


Summary

Below you can find a collection of the most important Node.js updates, tutorials & announcements from this week - curated by RisingStack's Node.js Developers.

Node v11.11.0 (Current) Released

Notable Changes:
  • n-api: Implement date object
  • util: Add compact depth mode for util.inspect()
  • worker:
    • Improve integration with native addons
    • MessagePort.prototype.onmessage takes arguments closer to the Web specification now

Node v10.15.3 (LTS) Released

Notable Changes:
  • doc: add antsmartian to collaborators
  • http: fix error check in Execute()
  • stream: fix end-of-stream for HTTP/2

Getting per-request context in Node.js with async_hooks

I recently got a problem when I was building a HTTP server in Node.js. I’m logging things in a lot of places inside my codebase and I have a unique ID for each request. I want to append this ID to each of my log messages to trace what’s happening in each request. How to efficiently do this?
If you are ready to use experimental Node.js stuff, I have a really elegant solution for you thanks to async_hooks.
Written by Guillaume Besson

Dynamic Configuration for Node.js Applications

Software systems that use dynamic configuration have the ability to change their configuration at runtime. The benefits of this pattern are vast and not altogether obvious. At GoDaddy, we use dynamic configuration in many of our Node.js applications to implement authorization, feature flags, and A/B tests, in addition to normal application configuration.
Read on to learn more about dynamic configuration, its many benefits, and how we’ve implemented it at GoDaddy using an in-house open source library called flipr.
Written by Grant Shively

Scaling the A3C algorithm to multiple machines with Tensorflow.JS and Node.js

The A3C algorithm was introduced by the Deepmind team at Google in 2016 : it can be considered a little bit old seeing how fast things are moving in AI, but A3C is still one of the most powerful deep reinforcement learning algorithms to date, and the idea behind it was exactly what I needed for the research project I was working on. It’s original approach however brought some limitations to the environment I set up, so I decided to revisit it in order to fit my needs.
This approach is implemented using Tensorflow.JS under NodeJS, making the problem more challenging and interesting."
Written by Naif Mehanna

Fudging Medium Stats with Node.js

This is not going be one of my usual articles in which we discuss how we can complete a certain task using the tools and frameworks at our disposal.
Instead, we will be using our superpowers for doing something evil, such as pumping up our medium stats (Views, Reads and Read Ratio). But before we proceed, I would like to point out that inflating stats is bad for obvious reasons, it’s not something that is public for others to view and it is certainly not an indication for how good or bad an article is. So, let’s start.
Written by Kashyap Mukkamala

REST in Peace. Long Live GraphQL!

Service oriented architecture and microservices have fundamentally changed the way we design and develop our applications in the past years. It’s up to us to adapt to this change and enrich our developer toolkit with one new addition: GraphQL.
This is an introductory talk to GraphQL I delivered for the Node.js Meetup community of Budapest in February 26, 2019. In this presentation I shared some of my experiences using GraphQL. Viewers are going to get familiar with GraphQL and related technologies and when (and when not) to apply them.
Written by Peter Czibik

Fixing UnhandledPromiseRejectionWarning in Node.js

JavaScript exhibits asynchronous behaviour for operations that are not completed immediately e.g a HTTP request or timer. These operations accept callbacks —  functions which are executed when an operation has been completed.
  1. setTimeout(function() { console.log('Slow and steady wins the race.'); }, 5000);
  2. console.log('The last shall be the first!');
If you’ve written JavaScript for a while, you’re probably familiar with callback hell. Callbacks can easily make code unreadable and difficult to reason about. Thankfully, we have Promises!
Written by Nicholas Kajoh

Two-Factor Authentication With TOTP Using Node.js And Speakeasy

Almost two years ago I had written a tutorial around 2FA in a Node.js API with time-based one-time passwords. If you’re unfamiliar, two-factor authentication is becoming the norm, which it wasn’t necessarily back in 2017. If you’re managing user accounts in your web applications, it is critical that you offer your users a second factor of authentication to prevent phishing and malicious login attempts.
While the previous tutorial is still valid, it uses a less popular library to accomplish the task. This time around we’re going to explore using a more popular library called Speakeasy to manage two-factor authentication (2FA) within our Node.js with Express.js application.
Written by Nic Raboy

Deploying a Scalable Web Application with Docker and Kubernetes

You don’t need to have Google- or Facebook-level traffic to care about making your web applications scalable. You might have a varying number of users, need to accurately predict your infrastructure costs, or just want to manage your systems more efficiently.
Learn how to test and deploy a Node.js app using containers and an orchestration engine.
Written by Joyce Lin

NVM, the Easiest Way to Switch Node.js Environments on Your Machine in a Flash

Switching between Node environments for local development is kind of a pain. It’s not easy, it’s something I forget to do frequently (until I have an unexplained issue during development), and frankly, it’s just not the easiest thing to do on a Mac.
This was my lot in life, until a co-worker clued me in to an awesome tool called Node Version Manager (NVM). NVM is a local development game changer. Let me tell you how.
Written by Paige Niedringhaus

Node.js TypeScript Readable Streams

Streams are present in programming for a long time now and it looks like they are going to stay. In Node.js they also play a big role and with them, we can deal with reading/writing data in an efficient way. You can encounter streams, for example, when working with files or dealing with HTTP requests. In this article, we cover the first of a few types of streams: the readable stream.
Written by Marcin Wanago

JavaScript Performance Pitfalls in V8

In recent years, JavaScript engines have improved on all fronts. The performance of JavaScript has reached a level where it can easily compete with programming languages that have traditionally been considered more appropriate for high-performance computing. This is not only true for V8, the JavaScript engine inside of Chrome and Node.js, but for all major JavaScript engines, including ChakraCore, the engine inside of Edge, JavaScriptCore, the engine inside of Safari, and SpiderMonkey, the engine inside of Firefox.
Not only did the peak performance improve, but engines also managed to deliver more consistent and predictable levels of performance. Given that JavaScript is a highly dynamic language, all of this performance is based on choosing the right heuristics in the engine. JavaScript engines use techniques like speculative optimization and inline caching to speed up execution of the likely path.
But heuristics can also easily work against you, and it helps to be aware of them. So today I’m gonna share some background on two subtle performance pitfalls in the V8 JavaScript engine. Being aware of these potential pitfalls might help you to resolve issues if you get bitten by these more easily.
Written by Benedikt Meurer
Previous Weekly Node.js Updates:
  • #Week 9 of 2019. 1 March
    • February 2019 Node.js Security Releases
    • Node.js Developer Roadmap
    • Node.js Logging Made Right
  • #Week 8 of 2019. 22 February
    • Node.js Selected by Google for .dev Top Level Domain
    • npm on the Security Risks of Changing Package Owners
    • 10 npm Security Best Practices
  • #Week 7 of 2019. 15 February
    • What security guidance would be most useful for Node.js developers?
    • Node.js v11.10.0 Current Released
    • Processing large volumes of data safely and fast using Node.js and PostgreSQL