Running Node.js on WSL from Visual Studio Code

Bartosz

October 27th, 2017

Starting with the October Insiders Build of Visual Studio Code we have added an easy way to run your Node.js applications on top of the Windows Subsystem for Linux (WSL). This is useful for developers targeting Linux or multiplatform production environments, making it possible to develop on Windows without relying on external systems or virtual machines.

We aimed at making running Node.js on WSL as easy and streamlined as possible. You will need Node.js installed and in your PATH in WSL, which can be easily done by following these instructions. In VS Code, all you need to do is add one new attribute to your launch.json :

"useWSL": true

This will make VS Code use WSL for running Node.js. Everything will work as expected, including debugging and custom runtimeExecutable settings:

Note: You will need Windows 10, build 15063 or later. If you are running an earlier version, you may encounter Error 0x80070057 when spawning WSL. If this happens you can try adding "console": "integratedTerminal" or "console": "externalTerminal" to your launch.json .

Native modules

In general, modules installed using Windows should work out of the box with Node.js spawned through WSL, and vice-versa, as long as they don’t have any dependencies on native modules. Special care is needed when native modules are used.

When using native modules in WSL, those also need to be built for the Linux platform. You can do that by running the following commands from the Windows shell in the project directory:

npm install bash -i -c "npm rebuild"

Bartosz Sosnowski and João Reis