The Node.js Update #Week 6, 8 February, 2019

RisingStack
5 min readFeb 8, 2019

--

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.

V8 release v7.3

The newest V8 version 7.3 is in beta until its release in coordination with Chrome 73 Stable in several weeks. V8 v7.3 is filled with all sorts of developer-facing goodies. This post provides a preview of some of the highlights in anticipation of the release, like:

  • Async stack traces
  • Faster await
  • Faster Wasm startup

& more..

React v16.8: The One With Hooks

Hooks let you use state and other React features without writing a class. You can also build your own Hooks to share reusable stateful logic between components.

Starting with 16.8.0, React includes a stable implementation of React Hooks for:

  • React DOM
  • React DOM Server
  • React Test Renderer
  • React Shallow Renderer

Note that to enable Hooks, all React packages need to be 16.8.0 or higher. Hooks won’t work if you forget to update, for example, React DOM.

ES2019 Features

Features and examples of new the new ES2019.

  • Array#{flat,flatMap}
  • Object.fromEntries
  • String#{trimStart,trimEnd}
  • Symbol#description
  • try { } catch {} // optional binding
  • JSON ⊂ ECMAScript
  • well-formed JSON.stringify
  • Function#toString
  • Array#sort stability

Generating PDF from HTML with Node.js and Puppeteer

In this article Mate Boer shows how you can generate a PDF document from a heavily styled React page using Node.js, Puppeteer, headless Chrome & Docker.

Background: A few months ago one of the clients of RisingStack asked us to develop a feature where the user would be able to request a React page in PDF format. That page is basically a report/result for patients with data visualization, containing a lot of SVGs. Furthermore, there were some special requests to manipulate the layout and make some rearrangements of the HTML elements. So the PDF should have different styling and additions compared to the original React page.

Node.js: How even quick async functions can block the Event-Loop, starve I/O

A typical Node.js app is basically a collection of callbacks that are executed in reaction to various events: an incoming connection, I/O completion, timeout expiry, Promise resolution, etc. There is a single main thread (a.k.a the Event-Loop) that executes all these callbacks, and thus the callbacks should be quick to complete as all other pending callbacks are waiting for their turn. This is a known and challenging limitation of Node and is also nicely explained in the docs.

Michael Gokman recently stumbled upon a real event-loop blocking scenario here at Snyk. When he tried to fix the situation, he realized how little he actually knew about the event-loop behavior and gained some realizations that at first surprised him and some fellow developers he shared this with.

Building a Node.js API with TypeScript and GraphQL

GraphQL is a query language for our API. It makes developing complex APIs a breeze by being strongly typed, which allows us to easily generate mocks for tests, documentation and automated optimizations.

This tutorials shows how easy it is to create a GraphQL server with Apollo, and that synchronizing your TypeScript and schema is not that difficult either.

45 Amazing Node.js Open Source Project Collection

This is an extremely competitive list and it carefully picks the best open source Node.js projects published between Jan and Dec 2018.

The tools and projects are broken down by 4 categories

  • Node.js Projects (1~12)
  • Web Building Tools (13~22)
  • Node.js Toolkits (23~41)
  • Server-side Tools (42~45)

Debugging Node.js Dependencies at Walmart

“Sometimes you have a fairly good idea of what packages were updated and it’s easy to figure out, but other times you might not even be aware that your problem is due to a downstream dependency being updated, and you’d be scratching your head for hours. While with the practice of lock file this is much better controlled, occasionally when you update your locks this could still happen. Usually we update locks one at a time, but could still result in getting new downstream from it, or sometimes we may want to do a refresh on the whole lock file.

In my daily job of supporting hundreds of Node.js developers, I have to debug this issue sometimes. This is a common problem that’s been around since early Node.js days. Before the practice of dependency lock file, we used to rely on npm-shrinkwrap.json and using precise versions instead of semver in package.json."

Will Node.js forever be the sluggish Golang?

HTTP request Time on Linux

No so called “web framework” for Node.js, whether Fastify or not, can surpass the red line. This is a pretty low upper limit as compared to trending alternatives like Golang.Luckily Node.js supports C++ addons, Google V8 bindings that link JavaScript to C++ and allows your JavaScript to invoke any behavior, even behavior that’s not provided by Node.js itself.

This post introduces uWebSockets.js: an alternative web server for JavaScript backends, written in ~6 thousand lines of C and C++, surpassing in performance the best of Golang by a large margin.

Benchmarking Go vs Node vs Elixir

In this benchmark test, the authors compare three web application servers — Go, Node, and Elixir — by subjecting each to a synthetic workload, first with 10k, and later with 100k connections.

“To simulate a generic web application client and server behavior, we have devised the following synthetic workload. The client device opens a connection and sends 100 requests with 900±10% milliseconds in between each one. The server handles a request by sleeping for 100±10% milliseconds, to simulate a backend database request, and then returns 1 kB of payload. Without additional delays, this results in average connection lifetime of 100 seconds, and average load of 1 request per second, per device.”

Originally published at community.risingstack.com on February 8, 2019.

--

--

RisingStack

Consulting, training & development services — with a strong focus on JavaScript, Node.js, DevOps, Microservices & Kubernetes | contact: info@risingstack.com