This tutorial is meant for users (developers) who are trying to run their existing Node.js applications on Windows.
For a long time, Windows users had a lot of issues being able to run Node applications on Windows, especially when dealing with very long names and installing modules that need to be compiled. This isn’t an issue of Node or Windows but the fact is, most developers were treating Windows as an afterthought. For this, Windows released a preview of Bash On Windows or WSL (Windows Subsystem Linux)
We won’t cover how to install WSL on Windows 10 and we will assume you already have access to Ubuntu Bash for Windows.
Launch Bash for Windows app and run:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
Install Visual Studio Code for Windows
Download from here
sudo apt-get install git
Clone the application
git clone http://github.com/youruser/application.git
To install node_modules you have two options:
- You can try to run npm install right from the current folder (windows mount). But you may run into file naming issues just like on Windows, or.
- You can symlink node_modules to your home folder (in Linux).
mkdir -p ~/node/mysite/node_modules
Please note that the folder you are linking from (~/node/mysite/node_modules) must be named node_modules otherwise, node won’t find them when you try to run the app.
Run the App
If everything goes well, you should be able to run node index.js (or whatever your application uses).
Even though launching node directly Visual Studio Code isn’t working well, you can debug the application by attaching to node.
First, launch the application in debug mode.
node -debug index.js
Then in Visual Studio Code open launch.js (from the .vscode folder) and edit the Attach section
remoteRoot is needed in order for breakpoints to properly work.
After this setup you should be able to run and debug applications built on Node.js
- New Features in WSL2 for Windows 10
WSL2 is coming to Windows 10. Discover the new features.