If you are a frontend developer you know how difficult is to test the code on windows especially if you are working on macOS.
There is only 1 solution to do that:
You need to create a virtual machine to run windows on your mac.
I know it can sounds difficult and you can think you need to spend a bunch of time but reading this article you will be able to set up everything 20 minutes maximum.
To do that we need to use Vagrant and VirtualBox and at the end I will like also to show you Ngrok. Let’s see how they work:
VirtualBox is a free and open source software for running virtual machines able to run Windows, Linux, and others.
Vagrant is an open source virtual machine manager, it takes care of installing the ISO image on the virtual machine.
With Vagrant is possible to build the virtual machines that you prefer (Windows, Ubuntu, etc…).
Ngrok exposes local servers behind NAT and firewall to a public Internet through secure tunnels.
It provides a public URLs for exposing your local web server making it available on different devices everywhere.
Let’s start from VirtualBox
At first you need to download VirtualBox from this link: https://www.virtualbox.org/wiki/Downloads
You should see something like that:
Now click on OS X hosts to download it and once you have installed open VirtualBox, you shouldn’t see any virtual machine because you didn’t create any ISO image.
It’s Vagrant time
Now we need to download Vagrant from the following link: https://www.vagrantup.com/downloads.html
You should see something like that:
Click on macOS to download it and once you have installed go here https://app.vagrantup.com/boxes/search and search windows 10
Now you should see this:
Click on the first item and now you should see this page:
click on new and it will give you a command line to create your vagrantfile and to create the ISO image on VirtualBox.
So now open your terminal and run this command:
vagrant init senglin/win-10-enterprise-vs2015community \
This command will create your Vagrantfile, the main functionality of the Vagrantfile is to describe the type of machine that you want to create (in our case windows 10).
Once you have it run:
This command will create your windows machine on VirtualBox based on the Vagrantfile, this command could take some time(10–15 mins) to be completed.
Now let’s run also
This command will drop you into a full-fledged SSH session, Now you can go ahead and interact with the machine and do whatever you want.
If you open VirtualBox you can see your windows machine like that
click on it and will open your windows machine, as password just type vagrant and voilà
But what if you want to show to somebody what we developed and we are running it on our localhost? Here Ngrok comes to help.
Last step: NGROK
Now let’s download NGROK from this url https://ngrok.com/download once you have done, unzip it and you will have a file exec, move it in your applications folder.
Now open a new window of the terminal and run:
now let’s bring our ngrok file from the applications folder to the bin folder. Why that? Because we would be able to use ngrok from everywhere in our pc. So let’s run:
ln -s /Applications/ngrok ngrok
Now the cool thing happens, because we will create a public URL that you are able to navigate everywhere!
If you are listening your project locally on http://localhost:3000 (for example) with ngrok we will transform the localhost in public URL.
To do that run:
ngrok http -host-header = http://localhost:3000
and you should see something like that:
This is the URL generated and here you go!