Tag Archives: node.js

Node-ChakraCore Update: N-API, Node.js on iOS and more

Today, we are happy to announce a new preview release of ChakraCore, based on Node.js 8, available for you to try on Windows, macOS, and Linux.

We started our Node-ChakraCore journey with a focus on extending the reach of Node.js to a new platform, Windows 10 IoT Core. From the beginning, it’s been clear that in addition to growing the reach of Node.js ecosystem, there’s a need to address real problems facing developers and the Node.js ecosystem though innovation, openness and community collaboration.

As we continue our journey to bring fresh new ideas and enable the community to imagine new scenarios, we want to take a moment to reflect on some key milestones we’ve achieved in the last year.

Full cross-platform support

While ChakraCore was born on Windows, we’ve always aspired to make it cross-platform. At NodeSummit 2016, we announced experimental support for the Node-ChakraCore interpreter and runtime on Linux and macOS.

In the year since that announcement, we’ve brought support for full JIT compilation and concurrent and partial GC on x64 to both macOS and Ubuntu Linux 14.04 and higher. This has been a massive undertaking that brings Node-ChakraCore features to parity across all major desktop operating systems. We are actively working on cross-platform internationalization to complete this support.

Support for Node.js API (N-API)

This year, our team was part of the community effort to design and develop the next-generation Node.js API (N-API) in Node.js 8 which is fully supported in ChakraCore. N-API is a stable Node API layer for native modules, which provides ABI compatibility guarantees across different Node versions & flavors. This allows N-API-enabled native modules to just work across different versions and flavors of Node.js, without recompilations.

According to some estimates, 30% of the module ecosystem gets impacted every time there is a new Node.js release, due to lack of ABI stability.  This causes friction in Node.js upgrades in production deployments and adds cost to native module maintainers in having to maintain several supported versions for their module.

Node.js on iOS

We are always delighted to see the community build and extend Node-ChakraCore in novel and interesting ways. Janea Systems recently announced their experimental port of Node.js to run on iOS, powered by Node-ChakraCore. This takes Node.js to iOS for the first time, expanding the reach of the Node.js ecosystem to an entire new category of devices.

Node.js on iOS would not be possible without Node-ChakraCore. Because of the JITing restrictions on iOS, stock Node.js cannot run. However, Node-ChakraCore can be built to use the interpreter only, with the JIT completely turned off.

This is particularly useful for scenarios like offline-first mobile apps designed with the expectation of unreliability connectivity or limited bandwidth. These apps primarily rely on local cache on the device, and use store and forward techniques to opportunistically use data connectivity when available. These kinds of apps are common in scenarios like large factory floors, remote oil rigs, disaster zones, and more.

Time-Travel Debugging

This year also brought the debut of Time-Travel debugging with Node-ChakraCore on all the supported platforms, as originally demoed using VSCode at NodeSummit 2016. This innovation directly helps with the biggest pain-point developers have with Node.js – debugging! With this release, Time-Travel Debugging has improved in stability and functionality since its introduction, and is also available with Node-ChakraCore on Linux and macOS.

 And much more …

These are just the start – our team has also made major investments in infrastructure automation, which have resulted in faster turnaround of Node-ChakraCore updates following the Node.js 8. Both stable Node-ChakraCore builds and nightlies are now available from the Node.js foundation build system.

We recently started measuring module compatibility using CITGM modules, and have improved compatibility with a wide variety of modules. Popular node modules like, node-sass, express and body-parser are considering using Node-ChakraCore in their CI system to ensure ongoing compatibility.  Node-ChakraCore also has improved 15% in ACMEAir performance on Linux in the last 2 months, and we’ve identified areas to make further improvements in the near future.

With our initial priority of full cross-platform support behind us, we are moving our focus to new priorities, including performance and module compatibility. These are our primary focus for the immediate future, and we look forward to sharing progress with the community as it happens!

Get involved

As with any open source project, community participation is the key to the health of Node-ChakraCore. We could not have come this far in our journey without the help of everyone who is active on our github repo, and in the broader Node community, for their reviews and guidance.  We are humbled by your enthusiasm and wish to thank you for everything you do. We will be counting on your continued support as we make progress in our journey together.

For those who are looking to get involved outside of directly contributing code, there are several ways to get involved and advance the Node-ChakraCore project. If you are a …

  1. Node.js Developer – Try testing Node-ChakraCore in your project, and use Time-Travel debugging with VSCode and let us know how it goes.
  2. Node.js module maintainer – Try testing your module with Node-ChakraCore. Use these instructions to add Node-ChakraCore in your own CI to ensure ongoing compatibility. If you run into issues, please let us know at our repo or our gitter channel.
  3. Native module maintainer – Consider porting your module to N-API. This will help insulate your module from breakage due to new Node releases and will also work with Node-ChakraCore.

As always, we are eager to hear your feedback, so please keep them coming. Find us on twitter @ChakraCore, our gitter channel or you can open an issue on our github repo to start a conversation.

Arunesh Chandra, Senior Program Manager, Chakra

Notes from the Node.js VM Summit

The Chakra team was delighted to host the third Node.js VM Summit recently here at Microsoft. These meetings bring together JavaScript VM vendors, Node collaborators, and CTC members including participants from Google, IBM, Intel, Microsoft, nearForm, and NodeSource. This group is currently focused on addressing ABI compatibility problems facing the Node native module ecosystem. Today, we’d like to share a quick recap of the meeting and some of the next steps.

Image showing VM Summit attendees in a conference room at Microsoft

Node Native Modules

Node native modules are written in C/C++ and directly depend on V8 and/or NAN APIs. These modules may need to be updated or re-compiled for every major Node.js release because of ABI/API changes. This adds to the maintenance burden for native module authors and it presents barrier to upgrading Node versions in production deployments for module consumers. The first half of the session included presentations from the two complimentary projects intended to help with this: Fast FFI (foreign function interface) and N-API (Node.js API).

Fast FFI

Fast FFI aims to automatically project native APIs into JavaScript which will allow module authors to expose existing native code to Node.js without having to write additional C/C++ code. The FFI presentation discussed its architecture and use cases. Currently, this project is in its early stages of prototyping and more work is required for it to be considered as a Node.js feature. We will update the community as we make progress and keep evaluating its readiness.

N-API

N-API provides an ABI-stable abstraction layer for native APIs in JavaScript VMs. This helps native module authors compile their module once per platform and architecture and run it on any N-API compliant version of Node.js. The N-API presentation included a demonstration of some ported modules and performance comparisons with their V8/NAN equivalents. N-API has made great progress over the last year and now it is ready for broader usage and feedback. As reflected in the graph below which shows native API usage pattern among top 30 depended-on modules, we have 100% N-API coverage for V8 APIs used in 5 or more modules.  The core team has successfully ported Node-Sass, Canvas, LevelDown, Nanomsg and IoTivity to use N-API.

Chart showing N-API Coverage in top third most-depended-on native modules. 195 total V8 APIs are used. Of these, 140 have an equivalent N-API.

N-API coverage for popular native APIs

VM Summit attendees evaluated the progress and readiness of both projects, and agreed to consider a pull request to include N-API in Node 8.0 as an experimental feature making it easier for native module authors to try out N-API and enable the team to test it broadly and get more feedback. The Fast FFI project will continue to evolve and may be included in a future Node.js release.

Key next steps for N-API project:

  • Submit N-API Pull Request to Node.js master to be included in Node.js 8.0
  • After stabilization, port it to Node.js v6.9 LTS and Node-ChakraCore
  • Broader community engagement to identify API gaps
  • Performance fine tuning

Other topics:

In the second half of the session the discussion focused on other VM compatibility topics including compatibility of the Inspector Protocol for debugging and baseline conformance requirements for Node.js VMs. The attendees also agreed on meeting again around NodeSummit later this year and evaluate progress on Fast FFI, N-API adoption, feedback and next steps.  

It was very a successful and productive VM Summit, and we look forward to feedback on the forthcoming N-API PR. You can review the full recording of the session here, review the raw notes from the meeting, or take an take an early look early look at the API here, Thanks to all the attendees for making the VM Summit awesome!

Arunesh Chandra, Senior Program Manager, Chakra

Node-ChakraCore and VM Neutrality in Node.js

Back when Node.js was launched, the device landscape was simpler, and using a single JavaScript VM helped provide Node.js the focus to grow rapidly. Today, there is a proliferation in the variety of device types, each with differing resource constraints. In this device context, we believe that enabling VM neutrality in Node.js and providing choice to developers across various device types and constraints are key steps to help the Node.js ecosystem continue to grow.

Node-ChakraCore started on this path last year by bringing Node.js to a new platform, Windows 10 IoT Core. As we chart the course for future of Node.js and promote the mission of Node.js everywhere, we’re excited to announce recent developments towards VM Neutrality, starting with Node.js API prototypes and progress towards cross-platform support in Node-ChakraCore.

The case for VM Neutrality

This growing trend of projects trying to port Node.js on to other VMs started a community discussion over whether Node.js should be VM neutral in the future, which led to this year’s VM Summit as an attempt to better understand the technical issues involved in achieving VM Neutrality.

VM Neutrality envisions Node.js as a ubiquitous application framework, highly optimized for any platform, device, or workload.  It describes a state of Node.js where Node Core is neutral to the JS Engine that is powering it via open standards & APIs, enabling a more formal interface between Node.js and the VM that powers it.

In a VM-neutral world, the Node.js ecosystem, especially native modules, will continue to seamlessly work on different JS VMs optimized for a variety of different devices and workloads. The benefits of VM Neutrality are many-fold:

  1. Reach/Ubiquity: Allows Node.js to target new devices and workloads with high optimization.
  2. Developer Productivity: Beneficial for developers as it provides cost savings by extending the reach of Node ecosystem and its ability to reuse code to target more devices and workloads.
  3. Standardized effort: Standardizes multi-VM efforts from already existing forks of Node.js

Node.js API (NAPI)

Node.js API (NAPI) is a community project being driven by the API working group, along with ChakraCore and others, with a goal of providing stable Node API for native module developers. NAPI aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs – allowing NAPI enabled native modules to just work across different versions and flavors of Node.js without recompilations.

NAPI is a stepping stone towards VM-Neutrality. After NAPI is officially available for native modules, it can be used inside Node core to achieve VM Neutrality and enable Node to seamlessly support multiple JavaScript engines. You can check out the first demo of a working NAPI prototype today at NodeInteractive Austin 2016!

Node-ChakraCore

In addition to supporting the NAPI efforts, Node-ChakraCore has been making progress on its cross-platform support and diagnostics innovation.

Update on Cross-platform support (Linux and macOS)

Bringing cross-platform support to Node-ChakraCore has been a key goal on our roadmap from the beginning. At NodeSummit we announced experimental support for Node-ChakraCore on Linux, and today bringing that same experimental support is available on macOS as well.

Screen capture showing an http-server sample with Node-ChakraCore displaying "Hello World" on macOS.

Running http-server sample on macOS with Node-ChakraCore

These early experimental builds have been validated against Node.js unit tests as well as some synthetic tests. We are looking for help hardening Node-ChakraCore further, so if you run into bugs while trying out these builds, please let us know on our issues page. Performance is a work in progress, with ongoing investments in the underlying ChakraCore engine. Please stay tuned for updates in this regard from the @ChakraCore team.

Time-Travel Debugging with Reverse Continue

One of the key internal guiding principles for us involved in the Node-ChakraCore project is to bring innovation to help advance the Node.js ecosystem. In that vein, we demoed a preview of Time-Travel debugging using VSCode earlier this year. This feature allows developers to capture trace of a running Node process, and then visualize the code execution inside of VSCode by stepping back in time. The “Step Back” functionality not only allows developers to understand the code execution path but also lets them inspect the runtime context using the typical debugger UI affordances.

Today, we are happy to announce that Time-Travel Debugging in VSCode on Windows has reached the Beta milestone, with better reliability, performance and a new feature called “Reverse Continue.”  This new feature is designed to work exactly like the “Debug Continue”, except that it goes backwards and is only available while debugging a TTD trace.

Animated gif of VSCode showing Time-Travel debugging with Step Back and Reverse Continue

VSCode showing Time-Travel debugging with Step Back and Reverse Continue

In addition, we are also making available a preview of Time-Travel debugging on our experimental Linux and macOS support.

Nightly Builds

The Node.js build system has now started producing nightly builds of Node-ChakraCore. Stable milestone builds will still be published on the Node-ChakraCore’s release page on Github.

Head over to the Node.js nightly build page and try it out.

Screen capture of the download page on nodejs.org showing chakracore-nightly build

Download page on nodejs.org showing chakracore-nightly build

What’s Next?

Our main focus in the short term is to continue working with the community to advance the NAPI project and VM-Neutrality goals. We are also working on performance improvements for cross-platform scenarios. Follow @ChakraCore on Twitter to stay tuned for updates on that work.

Get involved

We always love to hear from people trying out Node-ChakraCore for their own projects.  Today’s update makes it easier than ever before to get hands on with Node-ChakraCore on the platform of your choice. Take a look at the instructions to try out Node-CharkraCore and Time-Travel debugging with your existing apps and let us know if you run into problems on our issues page.

If you want to get more involved with the Node.js API efforts, here are some ways to get involved:

  • Convert a native module to use ABI stable APIs and report issues on conversion and performance;
  • Port ABI stable APIs to your fork of Node and let us know if there are gaps;
  • Review the roadmap and see how can you can help accelerate this project.

We’re excited to keep driving towards a VM-neutral future for the Node.js platform, and can’t wait to hear what you think!

― Arunesh Chandra, Senior Program Manager, ChakraCore

Windows IoT Core Extension for Visual Studio Code

About the Windows IoT Core Extension for VS Code

Visual Studio Code is the first code editor and first cross-platform development tool – supporting OS X, Linux, and Windows – in the Visual Studio family.

Windows 10 IoT Core already supports popular boards like Raspberry Pi2, MinnowBoard Max and DragonBoard, and because Node.js continues to see a lot of excitement in the maker community, we have been continuously improving and expanding the Node.js support for Windows 10 IoT Core.

Using Visual Studio Code and the new Window Iot Core Extension for VS Code, you can write a Node.js script, deploy it to a Windows IoT Core device and then run it from the development machine of your choice, whether it runs OS X, Linux or Windows.

Install VS Code

To get VS Code go to http://code.visualstudio.com. The setup is quick and easy! If you are new to VS Code, I suggest you check out VS Code Tips and Tricks: https://github.com/Microsoft/vscode-tips-and-tricks

Install Windows IoT Core Extension for Visual Studio Code

  • Start VS Code
  • Press F1
  • Type “Install extensions” and press enter
  • Type “iot” in the edit box at the top of the list
  • Click the install button on Windows IoT Core Extension for Visual Studio Code

Install Node

  • Go to https://nodejs.org/ in a browser
  • If you aren’t sure which version to install, then install the LTS version

Deploying the Hello World Sample to Windows IoT Core

To create a simple web server that displays “Hello World,” open a command prompt and execute the following commands:

  • md c:hello (directory name/location isn’t important)
  • cd c:hello
  • npm init (accept all defaults)
  • code . // code <space> <period/dot>
  • F1 -> iot: Initialize settings.json
  • Enter device IP address and desired name
  • Enter the username and password to log into the device with. The defaults are “Administrator” and “p@ssw0rd.” If you prefer not to have your username and/or password in a plain text file, delete these lines from the generated .json file and you will be prompted each time they are needed.
  • Verify that settings.json is correct by pressing F1 and then typing “iot: Get Device Info.” If the command succeeds you should see output similar to the following:

IMAGE1

  • Change LaunchBrowserPageNo in settings.json to LaunchBrowserPage
  • Add a new file to the workspace by clicking the icon found here. Name it index.js or whatever filename you provided in npm.init.

IMAGE2


        var http = require('http');
        http.createServer(function (req, res) {
            res.writeHead(200, { 'Content-Type': 'text/plain' });
            res.end('Hello World!n');
        }).listen(1337);

  • To enable logging of your project set the start script in package.json file. The log file will be written to C:datausersDefaultAccountAppDataLocalPackagesNodeScriptHost_dnsz84vs3g3zpLocalStatenodeuwp.log on the device.

{
    &amp;quot;scripts&amp;quot;: {
        &amp;quot;start&amp;quot;: &amp;quot;node --use-logger index.js&amp;quot;
    }
}

  • F1 > “iot: Run Remote Script”
  • Navigate to http://${deviceip}:1337/ in a browser

Deploying the Blinky Sample to Windows IoT Core

  • md c:blinky (directory name/location isn’t important)
  • cd c:blinky
  • npm init (accept all defaults)
  • code . // code <space> <period/dot>
  • F1 -> iot: Initialize settings.json
  • Enter device IP address and desired name
  • Enter the username and password to log into the device with. The defaults are “Administrator” and “p@ssw0rd”. If you prefer not to have your username and/or password in a plain text file, delete these lines from the generated .json file and you will be prompted each time they are needed.
  • Wire your circuit as described at https://developer.microsoft.com/en-us/windows/iot/samples/helloblinky
  • Add a new file to the workspace by clicking the icon found here. Name it index.js or whatever filename you provided in npm.init.

IMAGE3


    // Copyright (c) Microsoft. All rights reserved.
    var http = require('http');
    var uwp = require(&amp;quot;uwp&amp;quot;);
    uwp.projectNamespace(&amp;quot;Windows&amp;quot;);
    var gpioController = Windows.Devices.Gpio.GpioController.getDefault();
    var pin = gpioController.openPin(5);
    var currentValue = Windows.Devices.Gpio.GpioPinValue.high;
    pin.write(currentValue);
    pin.setDriveMode(Windows.Devices.Gpio.GpioPinDriveMode.output);
    setTimeout(flipLed, 500);

    function flipLed(){
        if (currentValue == Windows.Devices.Gpio.GpioPinValue.high) {
            currentValue = Windows.Devices.Gpio.GpioPinValue.low;
        } else {
            currentValue = Windows.Devices.Gpio.GpioPinValue.high;
        }
        pin.write(currentValue);
        setTimeout(flipLed, 500);
    }

  • F1 > “iot: Run Remote Script”
  • You should see the LED blinking

Quick Tour of IoT Commands

All of the commands contributed by this extension are prefixed with “iot:”. To see a list of commands that are contributed by this extension, press F1 and then type iot. You should see something like this:

iot: Get APPX Process Info    // get information about UWP applications running on the device

iot: Get Device Info          // get information about the Windows IoT Core device

iot: Get Device Name          // get the Windows IoT Core device name

iot: Get Extension Info       // get information about this extension

iot: Get Installed Packages   // get a list of APPX packages installed on the device

iot: Get Process Info         // get a list of processes running on the device

iot: Get Workspace Info       // get information about the workspace currently open in VS Code

iot: Initialize settings.json // initialize the project settings with iot extension defaults

iot: List Devices             // List Windows IoT Core devices on the network

iot: Restart Device           // Restart the Windows IoT Core device.

iot: Run Command Prompt       // Prompt for a command and then run it on the device

iot: Run Command List         // Show a list of commands from settings.json and run the one that is picked

iot: Run Remote Script        // Run the current workspace Node.js scripts on the Windows IoT Core device

iot: Set Device Name          // Set the device name using the IP Address and name provided

iot: Start Node Script Host   // Start the Node.js script host process that works with this extension

iot: Stop Node Script Host    // Stop the Node.js script host process that works with this extension

iot: Upload Workspace Files   // Upload the files for this workspace but don’t run the project

Get started with Visual Studio.

Advancing Node.js for Windows 10 IoT Core

One of the latest trends that has excited many technology enthusiasts in the last few years is Internet of Things (IoT), which has the potential to transform how technology is consumed by enterprises and end users in the coming years. Windows 10 IoT Core already supports popular boards like Raspberry Pi2, MinnowBoard Max and DragonBoard, and because Node.js continues to see a lot of excitement in the IoT and the maker community, we have been actively updating the Node.js support for Windows 10 IoT Core for new scenarios since it was released last year.

Yesterday, Node.js support for Windows 10 IoT Core reached a new major milestone. The Chakra team submitted a Pull Request(PR) to mainline Node.js using the recently open sourced ChakraCore JavaScript engine. Once accepted, this PR will allow us to move at the speed of Node.js while accomplishing two goals. First, growing organically based on community feedback and, second, bringing innovation faster to the developers on Windows 10 IoT Core. As per our roadmap, detailed in this blog, the Chakra team will continue to work closely with the community and the Node.js Foundation to improve module compatibility and evaluate Node.js performance.

The September update for Node.js support for Windows 10 IoT Core made it easier to get started and improved compatibility of some key IoT specific npm modules. This project continues to make progress by keeping it current with Node.js and incorporating community feedback. Today, we are releasing the version 1.5 update to Node.js Tools for Windows IoT. The following are some of the highlights of this new release.

Console Apps

The console application model constitutes a majority of Node.js development on Windows 10 IoT today. This is a familiar Node.js experience wherein developers are used to working with their favorite editor and a command prompt across platforms. Windows 10 IoT Core supported this app model from the beginning, allowing the use of Node.js with Chakra and using PowerShell, SSH, or SMB file transfer to manually deploy their scripts on the device. This experience will continue to work in the 1.5 update using Node.js with ChakraCore. ChakraCore will be developed in the open, will see faster updates, and will work across different Windows OS starting from Windows 7 and higher. Node.js with ChakraCore is aligned with Node.js master and currently supports Node.js v6.0.0. Developers can get started and try it out even with the standalone installer for Node.js with ChakraCore. You can use some of the console app samples like MemoryStatus and Using Cylon, which are available at our site.

Universal Windows Platform (UWP) Apps

Node.js developers for Windows 10 IoT Core also enjoy the benefits of Universal Windows Platform (UWP) model using Node.js. This app model is central to the Windows 10 ecosystem and allows developers to target the entire family of Windows 10 devices. UWP apps built using Node.js are powered by the inbox Chakra JavaScript engine, and the Node.js Tools for Windows IoT v1.5 will install all the relevant tools and binaries needed to create a UWP app in Node.js. This option allows familiar Visual Studio experience. The latest release includes better debugging support, more templates to help developers get started easily, and Node.js support for the latest stable release. It requires Visual Studio 2015 Update 1. The following are some key improvements for this scenario:

Support for Node.js Tools for VS 1.1
The latest NTVS release brings more reliable debugging and IntelliSense, support for npm v3, code snippets, and general stability and performance improvements.

Support for Node v5.4.1
We always want to be on the cutting edge of node.js and the latest build of Node.js Tools for Windows IoT supports the latest stable version v5.4.1

Built-in Template for Johnny-Five
Johnny-Five, a popular JavaScript Robotics and IoT programming framework, is well supported with Windows 10 IoT Core; with this release, we are making it even easier to get started with it by including a built-in UWP template for Johnny-Five.

New project dialog inside Visual Studio 2015 showing Johnny-Five UWP template

New project dialog inside Visual Studio 2015 showing Johnny-Five UWP template

Candy Robot

Our goal is to continue improving and also provide great Node.js support in Windows 10 IoT Core. As a part of the ChakraCore launch, we recorded a demo that showcases Node.js with the ChakraCore console app running on Raspberry Pi2 with Windows 10 IoT Core. We call it the “Candy Robot.” The demo shown here uses 100+ dependent npm modules including cylon, serialport, firmata, and express (there is also a version which uses Johnny-Five instead of cylon at our repo), just to illustrate the breadth of module support that is already available.

The Candy Robot has a light sensor on it. When it moves, the robot uploads the light intensity data at a given point to a server. The server has an interface to view the average brightness data and exploration time. It further shows an early preview of the Time-Travel debugging feature, which we are working on and will be sharing more about as it evolves.

If you want to play with it yourself and hook it up with some more interesting sensors and functionality, here is the detailed step-by-step instruction for the demo.

How to Get Started?

Want to build something interesting? To get started using Node.js Tools for Windows IoT, here are the instructions to create a UWP app and Node.js with ChakraCore console app. The Docs and Samples page has some samples with detailed instructions and code to play with.

It’s a lot of fun working on this project, and we truly value your support and feedback so far, so please keep them coming on our issues page. You can also reach us on Twitter at @ChakraCore or visit ChakraCore’s GitHub repo and leave us a note by opening an issue.

Can’t wait to see what you build!

Written by Arunesh Chandra, a senior program manager on Chakra

Submitting a Pull Request to Node.js with ChakraCore

Node.js continues to be a very successful and powerful cross platform technology for building apps that can run on anything from small IoT devices to large scale services that run in the cloud. We believe allowing more Node.js developers to target more platforms is key to its future growth. To do our part in growing the Node.js pie, last year we introduced support for Node.js with Chakra to extended the reach of Node.js and allowed developers to target a brand new platform called Windows 10 IoT Core. So far Node.js with Chakra has been actively updated and iterated upon at our own repository, with the intention to merge it with the mainline after stabilizing the code.

Today we hit that major milestone on our roadmap by submitting a pull request to Node.js mainline to enable Node.js to work with ChakraCore.

The recent open-sourcing of ChakraCore gives us the opportunity to develop in the open and align better with Node.js release schedules, in addition to expanding our support for Node.js across the broader Windows ecosystem – starting with Windows 7 SP1 and beyond. Here are some important things to know about this pull request.

Support for ChakraCore JS Engine

This pull request enables Node.js to optionally use the ChakraCore JavaScript engine. Chakra Shim, which is a layer on top of the ChakraCore JS Engine, enables building and running Node.js with ChakraCore. This shim implements the most essential V8 APIs so that the underlying JavaScript engine change is transparent to Node.js and other native addon modules written for V8. All that is needed is to rebuild Node.js executable and native addon modules with ChakraCore.

Diagram showing architecture of Node.js with ChakraCore using the Chakra Shim

Architecture: Extending Node.js with ChakraCore

ChakraCore is a fully capable JavaScript virtual machine that has the same key characteristics that are supported by Chakra. You can learn more about ChakraCore in our blog post announcing the project. ChakraCore is independent from Windows 10 and is supported on Windows 7 SP1 and up. We are working on taking ChakraCore cross-platform, starting with Linux, as described at the ChakraCore roadmap. ChakraCore also has capabilities to turn off JIT compiler and specify thresholds for resource consumption, both of which significantly reduce the resource requirements and make it attractive for resource constrained hardware scenarios.

State of module compatibility

npm modules are critical to any Node.js project. The vast majority of npm modules are JavaScript-based and should continue to work well with ChakraCore. There is a small subset of modules that are natively bound to V8 APIs and can run into compatibility issues with a different VM or even a different version of V8. This is the reason why Native Abstractions for Node.js (NAN) was born to allow for better module compatibility.

We embraced this abstraction and ensured all NAN based modules are fully supported in Node.js with ChakraCore. We also intend to actively participate in the native module abstraction efforts by contributing our learnings, architectural ideas, prototypes etc. in the community working group. While the abstraction effort is long-term approach, on a shorter term we would love to hear from the community on our issues page if there are any key compatibility gaps still remaining. This will allow us to prioritize the modules that need to be made compatible.

Evaluating Performance

JavaScript engine performance is key to any successful Node.js application or service. It impacts not only the user experience but also impacts cost for compute resources. Historically, the Chakra team has focused on real world performance over benchmark performance. To evaluate this, we tested TypeScript compile times, as it represents a large JavaScript program that can give us an indication of underlying JavaScript engine performance in the Node.js environment. The chart below shows various TypeScript workloads, compiled using the TypeScript compiler with Node.js and Node.js with ChakraCore. ChakraCore shows 10% -30% better throughput on these tests.

Chart showing Typescript compile times with Node.js. Node.js with ChakraCore is 10-30% higher throughput in these tests.

TypeScript compiler performance
(System info: Intel Core i5-34755 @ 2.90Ghz with 4.0GB RAM running Windows 10)

When compared to the baseline of default Node.js performance, Node.js with ChakraCore is more performant than Node.js with Chakra just a few months ago. The following graph plots slower-than-baseline tests below the blue line and the tests that were better than baseline above the blue line. While there’s still work to do, we’re happy that the curve is moving in the right direction.

Graph comparing Node.js benchmark performance (baseline) with Chakra and now with ChakraCore.

Node.js Benchmark performance
(System info: Intel Core i5-34755 @ 2.90Ghz with 4.0GB RAM running Windows 10)

Our performance testing did identify some differences in the hosting surface that can boost ChakraCore’s performance with Node.js. Continuing to invest in understanding and improving real world performance is a priority for the team. Going forward, we also want to work with the benchmarking workgroup and the community to identify real world performance scenarios for Node.js.

Looking ahead

The team is working on adding two key capabilities around diagnostics support. The first capability is focused on Modern Diagnostic APIs. While developers can use “console.log” style debugging when using Node.js with ChakraCore today, we are building a new set of Modern Diagnostic APIs, which break away from dependencies on COM and will help make the debugging experience of Node.js with ChakraCore interoperable with existing Node.js diagnostic tools. For the second, we are teaming up with Microsoft Research to advance the state of the art of Node.js debugging, with a feature we call Time Travel debugging.

Taking ChakraCore cross-platform is also high on our roadmap. Node.js is a truly cross-platform technology, and we believe that any JavaScript engine that powers it should be cross-platform as well. We are starting with Linux, and will keep the roadmap updated with details and status as we make progress. As a first step towards enabling cross-platform support, we have cleanly separated out Chakra’s JIT compiler producing a build configuration that builds just the interpreter and runtime. This smaller build target is what we will initially enable cross platform. We would love hear what the community thinks about which other platforms we should target. ChakraCore is open for taking contributions and if interested, we invite you to participate in porting ChakraCore to the platform of your choice.

You can participate or follow the work as it progresses on ChakraCore GitHub repository.

Try it out for yourself

You can try Node.js with ChakraCore with your existing scripts using this temporary installer, which installs Node.js with ChakraCore binaries without having to build it manually from the sources. We plan to work with the Node.js build working group to make these binaries available from an official Node.js channel. The current installer installs Node.js with ChakraCore side-by-side with an existing default Node.js installation without disturbing it, so that you can give it a try and share your feedback without disturbing your existing setup.

Our journey with Node.js has just started. We are committed to developing in the open, while working with the Node.js TSCs/CTC and the wider Node.js developer community. We truly see the power of Node.js, admire this community for what it has achieved so far, and we are excited to learn and contribute even more!

We welcome your feedback on our pull request to Node.js mainline. Try Node.js with ChakraCore and let us know your feedback. Finally, you can always reach us on Twitter at @ChakraCore or visit ChakraCore’s GitHub repository and leave us a note by opening an issue or via Gitter. We look forward to hearing from you!

Arunesh Chandra, Sr. Program Manager, Chakra

Gaurav Seth, Principal PM Manager, Chakra

Update on Node.js for Windows 10 IoT

Post written by Arunesh Chandra, Sr. Program Manager and Gaurav Seth, Principal Program Manager Lead on Chakra

Ever since we announced our preview of Node.js support for Windows 10 IoT Core a few months back, we have been working to enable new scenarios and improve its ease of use.  Here is what is new:

  1. Making it easier to get started

    Between studying the pin diagram to understand how to wire sensors on the board to getting the right bits on the device, the workflow of an IoT developer is already non-trivial, and the current experience of getting started with Windows 10 IoT using Node.js Chakra was a “high friction” process. Developers had to discover and install NTVS, NTVS IoT extension, and in some cases manually build Node.exe to work with Chakra etc.

    In order to improve this acquisition experience, we announce the availability of a bundle installer for Node.js tools for Windows IoT. This installs all the correct versions of the essential tools and also installs Node.exe, which works with Chakra. This installation works side by side in an existing default Node.js installation without disrupting it. The installer also creates the correct folder layout necessary to make node-gyp dependent node modules work without using any workarounds.

    1_nodeJsInstaller

    Please check out these steps which have links to detailed instructions on how to get started with your own Raspberry Pi 2 or other supported IoT device.

  2. Support for cylon, serialport and firmata

    We are committed to improving the compatibility of Node.js support on Windows IoT with npm modules. We started with popular modules for IoT scenarios. While this is a work in progress, we are happy to share that serialport, cylon and firmata are now fully supported.

    With this release we have also added a cylon project template and have a sample using serialport, cylon and firmata to help you get started with them. We have submitted a pull request (PR) on serialport to have it work by default on Node.js with Chakra.

    2_newNodeJsCylon

    Please let us know any other modules you are having trouble with when using Node.js with Chakra – it will help us prioritize our work better.

  3. Support for Node v4.0.0 and looking ahead

    Node v4.0.0 (stable) is out. We have been trying to keep up with the pace of change on this new converged repo to make Chakra work with Node v4 and submit a PR to the mainline.

    As the next step before we submit a PR on Nodejs/node (master), we have now published the code delta to enable Chakra on Node v4.0.0 on our repo to start getting early feedback on the same from key Node contributors and the Node community.

    Porting these changes to v4.0.0 required us to make some changes and additions to Chakra’s hosting APIs for external ArrayBuffer support. This support was added and previewed in the latest Windows Insider build. The latest Insider build also brings more advanced ES6 support with ES6 Classes, ES6 Generators, ES6 Destructuring, ES7 Async Functions and ES7 Exponentiation operator, among other ES6 features already supported by Chakra (see ES6 compat table).

    To run and test the abovementioned changes for Node v.4.0.0, join the Windows Insider Program and install the latest publicly-available Windows 10 flight.

    We understand that the above might not be ideal for all and thus we plan to submit a PR to the Node mainline as soon as these API updates become broadly available on Windows 10. We’ll of course inform the community once we know the exact timing.

Thanks for all the support so far! Your feedback is critical to this project and as always, we love to hear from you. So please keep it coming.