<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ivo Toby</title>
    <description>The latest articles on DEV Community by Ivo Toby (@buttonfreak).</description>
    <link>https://dev.to/buttonfreak</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F237103%2F115d30d1-2f79-4c64-afd8-a0750df22aa6.jpeg</url>
      <title>DEV Community: Ivo Toby</title>
      <link>https://dev.to/buttonfreak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/buttonfreak"/>
    <language>en</language>
    <item>
      <title>VSCode server on Azure Ubuntu VM. A step by step guide</title>
      <dc:creator>Ivo Toby</dc:creator>
      <pubDate>Sun, 09 May 2021 12:09:31 +0000</pubDate>
      <link>https://dev.to/buttonfreak/vscode-server-on-azure-ubuntu-vm-a-step-by-step-guide-38h5</link>
      <guid>https://dev.to/buttonfreak/vscode-server-on-azure-ubuntu-vm-a-step-by-step-guide-38h5</guid>
      <description>&lt;p&gt;In this article I'll explain step-by-step on how to create your own VSCode server running on a VM in Microsoft Azure.&lt;br&gt;
You do not need Azure, you can also use this guide on a VM on a home-server, any other cloud provider or a VM provided by your employer.&lt;/p&gt;
&lt;h2&gt;
  
  
  What to expect from this guide?
&lt;/h2&gt;

&lt;p&gt;After following these steps, you'll end up with a development server which you can use to work on Node.js frontend and backend projects. You could probably use it for other stacks. From my experience working with this setup is almost the same as running VSCode on your own machine, except it's not on your local machine.&lt;/p&gt;

&lt;p&gt;You can connect your local VSCode editor with the VSCode server using SSH. Code completion, 'go to definition', debugging, running your code, even the terminal, it's all the same. If you ever worked from VSCode on Windows with locally running containers or WSL ; it's exactly the same.&lt;/p&gt;

&lt;p&gt;Your development server will connect to your &lt;em&gt;Global Area Network&lt;/em&gt; using &lt;a href="https://www.zerotier.com/" rel="noopener noreferrer"&gt;ZeroTier&lt;/a&gt;. This makes it easy to connect without the need to change local configuration each time you start the server and it gets a new IP-address. Your development machine will be available from a local network. Nice bonus; you can completely fence the VM behind a firewall and still have SMB access.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Why would you want to run VSCode from a server?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Couple of reasons&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Resources&lt;/strong&gt;; a fairly complex webapp can contain a lot of files and do a lot of resource hungry stuff. My main development machine is a Macbook Pro 13'' from 2019. It has an Intel Core i7 and 16 GB of RAM. Should be enough, right? While working, most of you have other stuff running; Slack or other chat apps, an email client, your browser (most webdevs have several running at once), a music player. My Macbook does throttle a lot and gets pretty hot when working on a fairly large codebase in TypeScript. Using a dedicated VM will result in faster transpiling, faster response when testing your app, faster code completion and overall a more productive IDE/text editor.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security&lt;/strong&gt;; having the code I write for my employer sitting on a system from my employer is safe. If you're freelancing you can even use this as a USP; "everything I code for you is on systems you own".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility;&lt;/strong&gt; you can work from whatever machine you have within reach, as long as it is connected and has VSCode. Let me correct that; &lt;em&gt;as long as it has a decent browser&lt;/em&gt;. You can use a normal local VSCode instance to connect to your VSCode server, I'd recommend this as daily driver. However; since VSCode is a webapp you can also use your browser to connect to your VSCode server.  You can use a Chromebook, or even an iPad with a keyboard.  You have the full functionality you'd have when you use the VSCode application.
And since your code is not actually on the machine you're using it does not really matter if it's a company laptop or personal laptop.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Costs
&lt;/h2&gt;

&lt;p&gt;Free Microsoft credits aside, this VM will probably set you back around $25,- per month. You can shutdown the vm when you are not working, but you will need some grunt to comfortably run VSCode server. I use the &lt;em&gt;Standard B2ms (2 vcpus, 8 GB memory)&lt;/em&gt; VM-size which costs $70,- per month. That's steep, and you might get the same results use the B2s instance, which has 2 cores, 4GB of RAM and 16GB SSD and will set you back roughly $15,- per month. If you'd left it running a full month you'd be paying $35,- per month. I'll be testing the B2S instance upcoming week and will report back on my findings.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Update&lt;/em&gt; : after one morning working on the B2s instance I ran into memory issues. I had 3 projects open, 2 of them running (a serverless backend and a isomorphic frontend), I noticed the editor getting sluggish and &lt;code&gt;top&lt;/code&gt; revealed there was no RAM left. Since by default the Azure Linux VM's have no swap enabled the VM was slowly crashing. So I created a swap-file using the procedure described at the end of this article and I'm currently working with 4GB RAM and 5GB of swap.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;I assume you have all of the next items in place, or know a decent amount about;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An Azure account, either with credits or a valid creditcard and reasonable understanding of what Azure is, how to use it and the way the webapp works.&lt;/li&gt;
&lt;li&gt;Comfortable with Linux terminal, you know how to create a SSH-key, install packages&lt;/li&gt;
&lt;li&gt;You already have a ZeroTier account and the ZeroTier client installed on your own machine. There are a lot resources explaining setting up ZeroTier, so use the-Google for that (or read &lt;a href="https://www.stratospherix.com/support/setupvpn_01.php" rel="noopener noreferrer"&gt;this&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;If you want to secure the webinterface with an SSL certificate; a (sub)domain of which you can update the DNS records(recommended!)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Let's get started!
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a Virtual Machine in Azure in the region close to where you are, select whatever type you want and what youre credit card allows. I will be setting up a B2s instance, with 2 Cores and 4GB or RAM.

&lt;ul&gt;
&lt;li&gt;Select Ubuntu Server 21.04 - Gen1 as image.&lt;/li&gt;
&lt;li&gt;Use SSH public key authentication and use the key Azure creates or use a key you already have in place. Please note; you can not use ed25519 keys for now. Don't forget to enter a username to login.&lt;/li&gt;
&lt;li&gt;Network; for now allow SSH (22) and port 80 (service: http).&lt;/li&gt;
&lt;li&gt;Disks; depending on your needs you can add extra data disks.  For my situation the standard amount of 32 GB is enough.&lt;/li&gt;
&lt;li&gt;Management; Enable auto shutdown and set a time that's convenient for you, I use 9 pm, the likelihood of me still working at 9 pm is very slim.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;When the VM is up and running, connect to it with SSH. You can use the IP found at "Overview" in the Azure portal. If the SSH key you used is not the default key you can use the &lt;code&gt;-i&lt;/code&gt; argument to switch sshkeys like so:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -i ~/.ssh/id_rsa user@address
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;First thing I usually do is add my ed25519 key to ~/.ssh/authorized_keys (optional)&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Second thing; update the system;&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get upgrade
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Configure &lt;code&gt;max_user_watches&lt;/code&gt;. If you keep this at it's default value you might get errors like this &lt;code&gt;Error: ENOSPC: System limit for number of file watchers reached&lt;/code&gt; when you use node_modules like &lt;code&gt;nodemon&lt;/code&gt; or other file watchers in larger codebases. You can increase the value for &lt;code&gt;max_user_watches&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;fs.inotify.max_user_watches&lt;span class="o"&gt;=&lt;/span&gt;524288 | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; /etc/sysctl.conf &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;sysctl &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Now install ZeroTier:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-s&lt;/span&gt; https://install.zerotier.com | &lt;span class="nb"&gt;sudo &lt;/span&gt;bash
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;and add it to your virtual network ;&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;zerotier-cli &lt;span class="nb"&gt;join&lt;/span&gt; &amp;lt;your network-id from ZeroTier&amp;gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Authorize the client at the ZeroTier website and give it a static IP (by adding an address to the machine by hand on the website instead of letting the site decide).&lt;/p&gt;

&lt;p&gt;Disable the ubuntu firewall&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw disable
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;&lt;em&gt;Try to connect to the VM with SSH on its ZeroTier address before proceding. It could take a while before the virtual network is up &amp;amp; running, also after rebooting!&lt;/em&gt;&lt;/p&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Set a password for your user, you will need it to install packages from VSCode terminal&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;passwd &lt;span class="o"&gt;[&lt;/span&gt;your username]
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Optional: install zsh and oh-my-zsh&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install ZSH:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;zsh
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Set Zsh as default shell;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;chsh &lt;span class="nt"&gt;-s&lt;/span&gt; /bin/zsh &amp;lt;your username&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install oh-my-zsh, and the auto complete plugin (you will like it)&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sh &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;wget &lt;span class="nt"&gt;-O-&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh]&lt;span class="o"&gt;(&lt;/span&gt;https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
git clone https://github.com/zsh-users/zsh-autosuggestions &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;ZSH_CUSTOM&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="p"&gt;~/.oh-my-zsh/custom&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/plugins/zsh-autosuggestions
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the plugin to the list of plugins for Oh My Zsh to load (inside &lt;code&gt;~/.zshrc&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;plugins&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;git zsh-autosuggestions&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Download VSCode server from &lt;a href="https://github.com/cdr/code-server/releases" rel="noopener noreferrer"&gt;https://github.com/cdr/code-server/releases&lt;/a&gt;  and install it&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;wget &lt;span class="nt"&gt;-q&lt;/span&gt; https://github.com/cdr/code-server/releases/download/v3.9.3/code-server_3.9.3_amd64.deb
&lt;span class="nb"&gt;sudo &lt;/span&gt;dpkg &lt;span class="nt"&gt;-i&lt;/span&gt; code-server_3.9.3_amd64.deb
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Setup systemctl&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl --user start code-server
systemctl --user enable code-server
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;&lt;em&gt;Note; these commands are not run as sudo&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I've noticed that my code-server was not started at boot, because it's tied to my user-account. To allow starting at boot, use the following command;&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;loginctl enable-linger &amp;lt;your username&amp;gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Configure authentication by editing &lt;code&gt;~/.config/code-server/config.yaml&lt;/code&gt;. Set up a strong password, you won't need to change the IP-binding since we'll be setting up a reverse proxy.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;If you don't want to use the web interface and will only use SSH from another VSCode app you're basically ready, skip next steps to finish up.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;If you do like to use VSCode from a browser, move on to install NGINX and optionally Let's Encrypt.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Let's Encrypt&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need to set up a (sub)domain with an A record that points to the IP address assigned to the VM. For this tutorial I set up &lt;a href="http://vscode.syntacticsugar.nl" rel="noopener noreferrer"&gt;vscode.syntacticsugar.nl&lt;/a&gt; with a TTL of 60 seconds to ensure it's available quickly. You can change the IP to the IP you've assigned from ZeroTier in a later stage.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install Let's Encrypt:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;certbot &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Request the certificate:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;certbot certonly &lt;span class="nt"&gt;--standalone&lt;/span&gt; &lt;span class="nt"&gt;--agree-tos&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &amp;lt;enter your email&amp;gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &amp;lt;the domain you &lt;span class="nb"&gt;set &lt;/span&gt;up&amp;gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;em&gt;This could fail the first few times as DNS updates tend to be slower whenever you need them to be fast.&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When the certificate has been successfully created, change the DNS to the IP address you assigned in ZeroTier.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;NGINX reverse (SSL) proxy&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install NGINX:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;nginx &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create config:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /etc/nginx/sites-available/
sudo vim code-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you have setup SSL, paste this config :&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
 listen 80;
 server_name &amp;lt;YOUR DOMAIN&amp;gt;;
 # enforce https
 return 301 https://$server_name:443$request_uri;
}

server {
 listen 443 ssl http2;
 server_name &amp;lt;YOUR DOMAIN&amp;gt;;

 ssl_certificate /etc/letsencrypt/live/&amp;lt;YOUR DOMAIN&amp;gt;/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/&amp;lt;YOUR DOMAIN&amp;gt;/privkey.pem;

 location / {
 proxy_pass http://127.0.0.1:8080/;
 proxy_set_header Host $host;
 proxy_set_header Upgrade $http_upgrade;
 proxy_set_header Connection upgrade;
 proxy_set_header Accept-Encoding gzip;
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Activate the VHost;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /etc/nginx/sites-available/code-server /etc/nginx/sites-enabled/
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check the config&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nginx &lt;span class="nt"&gt;-t&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If all's fine, restart the services;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart nginx
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if you can reach code-server from your browser by going to &lt;a href="https://yourdomain" rel="noopener noreferrer"&gt;https://yourdomain&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Harden the firewall of your VM in the Azure Portal in the Networking Section. If you dare to rely on your ZeroTier connection you can disable SSH completely. If you're not the daring type consider only allowing connections to SSH from your own company or home IP. Also remove the rule for port 80.&lt;br&gt;&lt;br&gt;
If you are planning to use VSCode from a browser outside ZeroTier you can leave port 80 and add an allow rule for port 443. This is NOT recommended from a security point of view.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Optional: Next steps are for those that use Node.js, if you're into something else, please setup the tools you need in order to get some work done&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install NVM (node version manager, check &lt;a href="https://github.com/nvm-sh/nvm" rel="noopener noreferrer"&gt;https://github.com/nvm-sh/nvm&lt;/a&gt; for the latest version)&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-o-&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh]&lt;span class="o"&gt;(&lt;/span&gt;https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh&lt;span class="o"&gt;)&lt;/span&gt; | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Setup path in .zshrc;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Paste the following config at the end of the file;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;NVM_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.nvm"&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NVM_DIR&lt;/span&gt;&lt;span class="s2"&gt;/nvm.sh"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NVM_DIR&lt;/span&gt;&lt;span class="s2"&gt;/nvm.sh"&lt;/span&gt;  &lt;span class="c"&gt;# This loads nvm&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NVM_DIR&lt;/span&gt;&lt;span class="s2"&gt;/bash_completion"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NVM_DIR&lt;/span&gt;&lt;span class="s2"&gt;/bash_completion"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;log out and log in again&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now install the Node.js version you want to use (to list al available versions, use &lt;code&gt;nvm ls-remote&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;install &lt;/span&gt;v12.22.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install the global packages you might want to use&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Let's setup VSCode on your local machine to connect to your VSCode server. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install the &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack" rel="noopener noreferrer"&gt;VSCode Remote Development extension pack&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Open VSCode and click "Open Remote window" at the most bottom left corner
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn4c2hd9k220if6mmlc1p.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;Open SSH Configuration File&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Select the config file in your home directory/.ssh&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the following configuration (and modify it to reflect your environment)&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Host &lt;span class="o"&gt;[&lt;/span&gt;the &lt;span class="nb"&gt;hostname &lt;/span&gt;you used to create ssl or the Zerotier IP address &lt;span class="o"&gt;]&lt;/span&gt;
HostName &lt;span class="o"&gt;[&lt;/span&gt;the ZeroTier Ip address]
User &lt;span class="o"&gt;[&lt;/span&gt;your username]
IdentityFile ~/.ssh/id25519 &lt;span class="o"&gt;[&lt;/span&gt;or the SSH private key file you use to connect]
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now click the same button &lt;code&gt;Open Remote window&lt;/code&gt; , select  &lt;code&gt;Connect to host&lt;/code&gt; and select the host you just added.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If all is fine you should get an empty VSCode window, the button has changed and shows &lt;code&gt;SSH: [hostname]&lt;/code&gt;. &lt;br&gt;
&lt;strong&gt;Congrats; you are now working on your VSCode server!&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Next step; install plugins.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the plugins tab and scroll through the windows with locally installed plugins. Click &lt;code&gt;Install in SSH: [hostname]&lt;/code&gt; to install them on your VSCode server.  You probably need to close VSCode and reconnect.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Optional and highly recommended; install &lt;strong&gt;&lt;a href="https://www.kite.com/" rel="noopener noreferrer"&gt;Kite autocompletion&lt;/a&gt;&lt;/strong&gt;.  Kite adds AI powered code completions to your code editor, giving you superpowers. You do not need to install kite on your local machine and kite will work if you use your browser to work in VSCode.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;bash &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;wget &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="nt"&gt;-O&lt;/span&gt; - &lt;span class="o"&gt;[&lt;/span&gt;https://linux.kite.com/dls/linux/current]&lt;span class="o"&gt;(&lt;/span&gt;https://linux.kite.com/dls/linux/current&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

systemctl &lt;span class="nt"&gt;--user&lt;/span&gt; start kite-autostart
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You need to restart vscode server after installing Kite;&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl &lt;span class="nt"&gt;--user&lt;/span&gt; restart code-server
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnkqvammzaedjubjcsy35.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnkqvammzaedjubjcsy35.png" alt="Kite giving suggestions from the webinterface"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tips and tricks and daily usage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Getting started in the morning
&lt;/h3&gt;

&lt;p&gt;I have not found an easy way to autostart my VM every morning. To be honest; I don't think I need that either. I have days with back to back meetings and I don't want the VM burning to my Azure credits without me using it. &lt;br&gt;
So I login to the Azure portal and start it manually every time I need it. When it's up and running I connect my local VSCode app and hack away. &lt;br&gt;
&lt;em&gt;Update&lt;/em&gt;: I stumbled upon the Azure App for iOS, this app makes it very easy to start your development VM.&lt;/p&gt;
&lt;h3&gt;
  
  
  Portmapping
&lt;/h3&gt;

&lt;p&gt;If you run a project using node you'd normally fire up a browser and navigate to &lt;a href="http://localhost:port" rel="noopener noreferrer"&gt;http://localhost:port&lt;/a&gt; . &lt;em&gt;Using VSCode server is exactly the same!&lt;/em&gt; VSCode will create SSH tunnels for you so you can connect to localhost:portnumber. So you won't run into CORS issues or other strange behaviour. &lt;/p&gt;
&lt;h3&gt;
  
  
  Opening a VSCode window from the VSCode terminal
&lt;/h3&gt;

&lt;p&gt;Imagine; you are working on a frontend from on your VSCode server from a local VSCode instance using SSH. You realize you need to check some stuff in another project, which has been cloned into another folder on your VSCode server. You can &lt;code&gt;cd&lt;/code&gt; to that project using the terminal within VSCode and fire up a new editor by simply typing &lt;code&gt;code .&lt;/code&gt; &lt;/p&gt;
&lt;h3&gt;
  
  
  Finishing up for the day
&lt;/h3&gt;

&lt;p&gt;You had a productive day writing elegant code and finishing several tickets. You're ready for a quiet evening doing other stuff. Before closing the lid of your laptop be sure to save ALL files in VSCode and commit &amp;amp; push your work. Your VM will shut down later tonight which could lead to data loss. I have not run into this, but better safe than sorry right?&lt;/p&gt;
&lt;h2&gt;
  
  
  Known Issues
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It could take a while for ZeroTier to connect after booting the server. If you have issues ZeroTier not connecting at all try to login using SSH with the dynamic IP assigned by Azure and run ZeroTier join command; &lt;code&gt;sudo zerotier-cli join &amp;lt;your network-id from ZeroTier&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The VSCode webinterface might work better if you use Chrome.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Not enough memory? Enable swap on your Azure VM;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;edit &lt;code&gt;/etc/waagent.conf&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;add or uncomment these lines (set &lt;code&gt;SwapSizeMB&lt;/code&gt; to match the amount of RAM your VM or more) :&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ResourceDisk.Format=y
ResourceDisk.Filesystem=ext4
ResourceDisk.MountPoint=/mnt/resource 
ResourceDisk.EnableSwap=y
ResourceDisk.SwapSizeMB=4096
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;reboot your VM and you should see swap memory in &lt;code&gt;top&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Questions? Praise? Complaints?
&lt;/h2&gt;

&lt;p&gt;Email :  &lt;a href="//mailto:i.toby@wearetriple.com"&gt;i.toby@wearetriple.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Twitter: &lt;a href="https://twitter.com/buttonfreak" rel="noopener noreferrer"&gt;https://twitter.com/buttonfreak&lt;/a&gt; &lt;a href="//mailto:i.toby@wearetriple.com"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>node</category>
      <category>azure</category>
      <category>bofh</category>
    </item>
  </channel>
</rss>
