What's New for Node.js in 2020

What's New for Node.js in 2020

What's New for Node.js in 2020? What’s New in Node.js Version 13? In 2019, Node.js turned 10 years old, and the number of packages available on npm crossed one million. Node.js joined the OpenJS Foundation, which promises to improve project health and sustainability, as well as improve collaboration with the JavaScript community at large.

In 2019, Node.js turned 10 years old, and the number of packages available on npm crossed one million. Downloads for Node.js itself continues to rise, growing 40% year over year. Another significant milestone is Node.js recently joined the OpenJS Foundation, which promises to improve project health and sustainability, as well as improve collaboration with the JavaScript community at large.

As you can see, a lot has happened in a relatively short amount of time! Every year the Node.js community has gained momentum, and 2020 shows no signs of slowing down.

There are lots of interesting features being explored for the next major releases of Node.js. In this post I’ll explore some of the most significant updates the Node.js community can expect in 2020.

What’s New in Node.js Version 13?

As of this writing, the most recent release of Node.js is 13. There are already a number of features and updates we can start playing around with leading into 2020. Here’s a list of highlights:

  • ECMAScript modules
  • WebAssembly support
  • Diagnostic reports
  • Full internationalization support for date, time, number, and currency formats
  • QUIC protocol support
  • V8 JavaScript engine performance updates

Before I dive into the details of these updates, let’s take a look at what we can expect from the Node.js release schedule.

The Node.js Release Process for 2020

Every six months, a new major version of Node.js is released, one in October and one in April. This major version is referred to as the Current version. As of this writing, the Current version of Node.js is 13, released in October 2019.

Odd-numbered versions (e.g. v9, v11, and v13) are released every October, are short-lived, and are not considered ready for production. You might think of an odd-numbered version as a beta version. They are designed for testing new features and changes leading up to the next even-numbered version of Node.js.

Even-numbered versions (e.g. v8, v10, and v12) are released every April. After its release, the previous odd-numbered version will stop receiving updates. Although more stable than odd-numbered versions, it will continue to be actively developed for the next six months. You could think of this first six months as a release candidate stage.

Once an even-numbered version has had time to bake for six months, it enters a new stage of life called Long-Term Support (LTS). The LTS stage is considered production-ready. For the next 12 months, LTS versions receive bug fixes, security updates, and other improvements with the goal of not breaking any existing applications.

After LTS, there is a final Maintenance stage. While in Maintenance, the Node.js version will only receive critical bug and security fixes. The Maintenance stage lasts for 18 months. After 18 months of Maintenance, it is considered End-of-Life (EOL) and is no longer supported.

Expected Release Schedule for 2020

We should expect to see the following release schedule in 2020.

January - March 2020

  • 13.x is the Current version and actively developed
  • 10.x and 12.x are LTS

April 2020

  • 14.x released and becomes the Current version
  • 13.x work stops soon after 14.x release
  • 10.x enters Maintenance

October 2020

  • 15.x released and becomes the Current version
  • 14.x enters LTS
  • 12.x enters Maintenance

Note: Node 8.x End-of-Life (EOL) is scheduled at the end of 2019 due to its dependency on OpenSSL-1.0.2, which is also scheduled for EOL at the end of 2019. If you haven’t already, make plans to migrate 8.x applications to 10.x or 12.x.

Support for ECMAScript Modules

As of v13.2.0, Node.js supports both traditional CommonJS modules and the new standard ECMAScript (ES) modules out of the box. This means you can finally use import and export syntax you may already be using for client-side JavaScript running in the browser. Also, it’s important to note ES modules in Node.js have JavaScript strict mode enabled by default, so you don’t have to specify "use strict"; at the top of every file.

// message file
async function sendMessage { ... }
export { sendMessage };

// index file
import { sendMessage } from "./message";

However, you still need to do a little work to let Node.js know you are using ES modules. The two most common ways to do this are using the .mjs file extension or specifying "type": "module" in the nearest parent package.json file.

  • Option 1: Rename .js files to .mjs files.
  • Option 2: Update the root package.json file, or add a package.json to the folder that contains ES modules and specify the type as module.
{
   "type": "module"
}

Another possibility is enabling ES module in the root package.json file, and then renaming all CommonJS module files to use the .cjs extension.

Personally, I find the .mjs and .cjs extensions a little gross, so I’m glad to see there are ways of specifying ES and CommonJS module usage with a package.json file.

Node.js can Import WebAssembly Modules

Along with ES module support comes the ability to import WebAssembly (Wasm) modules! A WebAssembly module is a portable compiled binary format that can be parsed faster than JavaScript and executed at native speeds. WebAssembly modules can be created using a language such as C/C++, Go, C#, Java, Python, Elixir, Rust, and many others.

WebAssembly module support is still in the experimental stage as of this writing. To enable the feature, you must pass a command-line flag when executing a Node.js application. For example:

node --experimental-wasm-modules index.js

As an example, imagine you have an image processing library implemented as a WebAssembly module. The syntax for using this Wasm module might look like the following.

import * as imageUtils from "./imageUtils.wasm";
import * as fs from "fs";
( async () => {
   const image = await fs.promises.readFile( "./image.png" );
   const updatedImage = await imageUtils.rotate90degrees( image );
} )();

It’s also possible to import a WebAssembly module using the new dynamic import() statement in Node.js.

"use strict";
const fs = require("fs");
( async () => {
   const imageUtils = await import( "./imageUtils.wasm" );
   const image = await fs.promises.readFile( "./image.png" );
   const updatedImage = await imageUtils.rotate90degrees( image );
} )();

WebAssembly System Interface (WASI)

Similar to JavaScript, WebAssembly is designed with security in mind to prevent access to any of the underlying operating system, sometimes referred to as “sandboxed.” However, there are times when a WebAssembly module in your control in Node.js may benefit from being able to make system-level calls.

This is where the new WebAssembly System Interface (WASI) comes in. WASI is designed to be a standard interface for making calls to the underlying system, such as the host application, native operating system, and so forth.

Initial WASI support was recently committed to the Node.js project. WASI is another exciting feature we may see come to Node.js in 2020!

Diagnostic Reports Launch in 2020

Diagnostic reports are human-readable JSON-formatted summaries of process information, including call stacks, operating system information, loaded modules, and other useful data designed to assist in supporting applications. These reports can be triggered on unhandled exceptions, fatal errors, a process signal, or using the new process.report API. Node.js can be configured to save diagnostic reports to a specified folder and file name.

As of this writing, diagnostic reports are in the experimental. To enable this feature, you must pass a command-line flag when executing a Node.js application. For example:

node --experimental-report --report-uncaught-exception --report-filename=./diagnostics.json index.js

Internationalization Support Expands in 2020

As of v13.x, Node.js comes compiled with full ICU (International Components for Unicode). ICU is a mature and popular globalization library. Among many features, ICU includes support for formatting numbers, dates, times and currencies, performing time calculations and string comparisons, and converting text between Unicode and other character sets.

Other Node.js Updates for 2020
  • QUIC protocol support: a modern transport for connected applications with increased performance and reliability.
  • Better Python 3 build support: in 2020 it should be possible to build Node.js and native modules using Python 3.
  • An Updated V8 JavaScript engine: V8 v7.8 and 7.9 increase performance and Wasm support.
  • Stable Workers Threads API: Worker threads in Node.js enable parallel, CPU-intensive JavaScript operations.

Originally published by David Neal at https://developer.okta.com

Node.js for Beginners - Learn Node.js from Scratch (Step by Step)

Node.js for Beginners - Learn Node.js from Scratch (Step by Step)

Node.js for Beginners - Learn Node.js from Scratch (Step by Step) - Learn the basics of Node.js. This Node.js tutorial will guide you step by step so that you will learn basics and theory of every part. Learn to use Node.js like a professional. You’ll learn: Basic Of Node, Modules, NPM In Node, Event, Email, Uploading File, Advance Of Node.

Node.js for Beginners

Learn Node.js from Scratch (Step by Step)

Welcome to my course "Node.js for Beginners - Learn Node.js from Scratch". This course will guide you step by step so that you will learn basics and theory of every part. This course contain hands on example so that you can understand coding in Node.js better. If you have no previous knowledge or experience in Node.js, you will like that the course begins with Node.js basics. otherwise if you have few experience in programming in Node.js, this course can help you learn some new information . This course contain hands on practical examples without neglecting theory and basics. Learn to use Node.js like a professional. This comprehensive course will allow to work on the real world as an expert!
What you’ll learn:

  • Basic Of Node
  • Modules
  • NPM In Node
  • Event
  • Email
  • Uploading File
  • Advance Of Node

How to get started Internationalization in JavaScript with NodeJS

How to get started Internationalization in JavaScript with NodeJS

Tutorial showing how to use the Intl JS API in NodeJS (i18n). We'll install a module to unlock the Intl API languages for Node and test out RelativeTimeFormat to translate and localise relative times in JavaScript.

Tutorial showing how to use the Intl JS API in NodeJS (i18n). We'll install a module to unlock the Intl API languages for Node and test out RelativeTimeFormat to translate and localise relative times in JavaScript. I'll tell you how to get started with the built-in internationalization library in JS for Node 12 and higher. We'll change the locale to see how the translation works and test different BCP 47 language tags.

Internationalization is a difficult undertaking but using the Intl API is an easy way to get started, it's great to see this new API in the JS language and available for use. Soon, you'll be able to have confidence using it in the browser as modern browsers support the major Intl features. Have a look at the browser compatibility charts to see which browsers and versions of node are supported.

Use Intl.RelativeTimeFormat for language-sensitive relative time formatting.
#javascript #nodejs #webdevelopment

MDN Documentation:

https://developer.mozilla.org/en-US/d...

Full ICU NPM package:

https://www.npmjs.com/package/full-icu

What is WebAssembly? What does it mean for JavaScript and Node.JS?

What is WebAssembly? What does it mean for JavaScript and Node.JS?

What is WebAssembly? Is it going to replace JavaScript?! Signs say no, but it still has the potential to have a huge impact on JavaScript development in the browser and in Node.JS.

WebAssembly has been around for years but is only just starting to gain real traction in the developer space. What is WebAssembly? Is it going to replace JavaScript?! Signs say no, but it still has the potential to have a huge impact on JavaScript development in the browser and in Node.JS. Let’s walk through the how and why of this amazing new language feature through code and discussion.

Speaker: Mx Kassian Wren | DevRel, Cloudflare.

--

WebAssembly and the future of Web development

WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications.

WebAssembly gives developers a way to write optimized code routines, usually in C++. This is powerful ability, but it has a relatively narrow scope. It’s useful if you need to improve the performance of complex calculations. (For example, fastq.bio used WebAssembly to speed up their DNA sequencing calculations.) It’s also important if you’re porting high-performance games or writing an emulator that runs inside your browser. If this is all there were to WebAssembly, it wouldn’t be nearly as exciting — and it wouldn’t have any hope of displacing JavaScript. But WebAssembly also opens a narrow pathway for framework developers to squeeze their platforms into the JavaScript environment.

Here’s where things take an interesting turn. WebAssembly can’t sidestep JavaScript, because it’s locked into the JavaScript runtime environment. In fact, WebAssembly needs to run alongside at least some ordinary JavaScript code, because it doesn’t have direct access to the page. That means it can’t manipulate the DOM or receive events without going through a layer of JavaScript.

This sounds like a deal-breaking limitation. But clever developers have found ways to smuggle their runtimes in through WebAssembly. For example, Microsoft’s Blazor framework downloads a miniature .NET runtime as a compiled WASM file. This runtime deals with the JavaScript interop, and it provides basic services (like garbage collection) and higher-level features (layout, routing, and user interface widgets). In other words, Blazor uses a virtual machine that lives inside another virtual machine, which is either an Inception-level paradox or a clever way to create a non-JavaScript application framework that runs in the browser.

Blazor isn’t the only WebAssembly-powered experiment that’s out of the gate. Consider Pyodide, which aims to put Python in the browser, complete with an advanced math toolkit for data analysis.

This is the future. WebAssembly, which started out to satisfy C++, Rust, and not much more, is quickly being exploited to create more ambitious experiments. Soon it will allow non-JavaScript frameworks to compete with JavaScript-based standbys like Angular, React, and Vue.

And WebAssembly is still evolving rapidly. It’s current implementation is a minimum viable product — just enough to be useful in some important scenarios, but not an all-purpose approach to developing on the web. As WebAssembly is adopted, it will improve. For example, if platforms like Blazor catch on, WebAssembly is likely to add support for direct DOM access. Browser makers are already planning to add garbage collection and multithreading, so runtimes don’t need to implement these details themselves.

If this path of evolution seems long and doubtful, consider the lessons of JavaScript. First, we saw that if something is possible in JavaScript, it is done. Then, we learned that if something is done often enough, browsers make it work better. And so on. If WebAssembly is popular, it will feed into a virtuous cycle of enhancement that could easily overtake the native advantages of JavaScript.

It’s often said that WebAssembly was not built to replace JavaScript. But that’s true of every revolutionary platform. JavaScript was not designed to replace browser-embedded Java. Web applications were not designed to replace desktop applications.