Running NodeJS on Linux on Windows (with no VM)

David Gilbertson
Nov 14, 2016 · 6 min read

Hello fellow Windows-using web developers. How you doin’?

I know I know, life isn’t easy. All those Mac users making fun of us with our uncool laptops and operating system that shared a womb with IE6. The Linux people can’t even look at us without chortling, I’m sure they’re making puns that involve obscure commands behind our backs.

We know that Windows is the best looking and fastest operating system, but they don’t seem to care. Apparently being able to type ‘grep’ is more important than all that.

Well happy days, comrades! You can now run Linux Bash in Windows and get emacs and vi and ssh and whatever else might float one’s boat. Right there in your favourite little black window.

Since you’ve no doubt already been distracted by the gaudy gif below, I’ll explain what’s happening. I am opening command prompt (Windows), entering Bash (Linux), running a Node server (Linux) on localhost and opening that in Chrome (Windows).

Note that it takes exactly no seconds to load Linux.

It’s called WSL, or Windows Subsystem for Linux if you need a tongue workout. There are some system requirements. You’re smart, you’ll work out what they are.

WSL in action

I start with a good old fashioned command prompt, sexy as always. I run node which of course runs the instance of Node that I have installed in Windows. I use the platform() method of Node’s os module to print the platform name so you believe me that this is Windows.

I then exit Node and run bash to step into Linux. Now I run node again, but I’m in a Linux bash, so it’s the instance of Node I have installed for this Linux instance (we’ll get to the instructions below, settle down).

Now when I type os.platform() I see that I’m on Linux. Amazing! Ctrl+D will break out of Node, then again will break me out of Linux and back to the Windows command prompt.

This pleases me a great deal, so I wrote a poem:

Runnin’ Node in Windows

Runnin’ Node in Linux

Oh I’m runnin’ Node in Windows

[cracks whip] [cracks whip]


I’m going to assume that you’re more excited than you’ve ever been and want to know exactly how you can partake in such wonderment.

Well alright then…

Step by step…

  • Type “windows features”
  • Hit Enter
  • Tick the Windows Subsystem for Linux box
  • Click OK
  • Hit Start
  • Type “powershell”
  • Right click it and click Run as administrator
  • Type Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  • Hit Enter
  • Restart. This isn’t one of those things where it says you need to restart but you don’t really need to restart. You really need to restart.

After the restart….

  • Hit Start
  • Type “cmd”
  • Hit Enter
  • In the command prompt type bash and hit Enter.

This is how you launch the instance of Linux. Since it’s the first time you’ve done this, it will kick off the download of the Ubuntu image from Canonical (which is the non-GUI ‘user-mode Linux’, similar in concept to Windows Server Core). In future, you can access Linux bash in one of two ways:

  1. Open a command prompt and type bash
  2. Run the dedicated Bash on Ubuntu on Windows app which I snuck in and installed while you were reading my poem

You now have a nice clean install of Linux ready to go, so let’s…

Install NodeJS

curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y nodejs

(Or whatever version you want.)

Now you’ve got Linux and Node. This is easy, right?

So what exactly is happening here?

I found it all a bit mind bending at first; the trick is not to think about it.

You want more?

What are some random tips on accessing the command prompt?

From Explorer with mouse

secret-squirrel right click menu

From Explorer — weird shortcut

Weird, right? I discovered this cleaning my keyboard one day.

Set the default path for a command prompt

You can then enter a value for Start in, which is the directory command prompt will … start in.

Don’t forget to pin that icon to the taskbar. Now when you click the icon to open command prompt it will open in the correct directory.

Can I set this as my default terminal in WebStorm?

How does this interact with the network and filesystem?

Do all of the filesystem/network feature of NodeJS work with this?

Will it work with file watching and hot reloading?

[cracks whip]

Hacker Noon is how hackers start their afternoons. We’re a part of the @AMI family. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.

If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!

HackerNoon.com

how hackers start their afternoons.

David Gilbertson

Written by

I like web stuff.

HackerNoon.com

how hackers start their afternoons.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade