How to set up a Node.js development environment on an iPad using Google Cloud Platform
I wanted to use some idle time during my holidays to work on a Node.js app that I‘ve been playing with for a while. As I only brought my iPad, I had to figure out how to set up a development environment on this machine. My conclusion: It isn‘t the most comfortable way to write code, but it works. Here is how I did it:
Due to iOS restrictions, there is no way to run Node.js on an iPad, which means I had to use the iPad as a terminal to work on a cloud server.
Spin up a development server
As I‘m deploying the app on Google Cloud Platform (GCP) anyways, I simply used Google‘s Node.js application runtime template to spin up a development server in a Google Compute Engine instance. There are similar templates for other cloud providers, so feel free to use AWS, DigitalOcean, or whatever service you prefer.
Connect via SSH
Once the instance is booted, you need to connect with the server via SSH. Prompt by Panic, Inc. is my SSH client of choice on iOS. Within Prompt, generate a SSH key and copy the public key to the clipboard. In the GCP concole, go to Compute Engine > Metadata > SSH Keys and add the SSH key by pasting it from the clipboard, followed by a space and the username you want to use to connect to the server. If needed, check out the GCP documentation on that matter.
Now copy the external IP assigned to the cloud server and add a connection in Prompt, using the IP as well as the username and the key you created earlier.
Update NPM and Node.js
Update NPM to the latest version:
sudo npm install npm@latest -g
Update Node.js to the latest version
sudo npm install -g n && sudo n latest
Connect the development server to GitHub
In order to be able to check out your code repository from GitHub onto the development server, create a SSH key on the cloud server (see the GitHub documentation for details).
ssh-keygen -t rsa -b 4096 -C “email@example.com”
Copy the newly created SSH key, for example by opening the generated key file. I used Coda (also from Panic, Inc.) to connect to the server (using the same IP, username and key that I used in Prompt) and access the key file, because I‘m also using Coda to do all the coding on my iPad.
Once the SSH key is copied, add it to your SSH keys in GitHub. Now you can clone your GitHub repository onto the development server:
git clone firstname.lastname@example.org:<user>/<repository>.git
Now you can run your Node.js app and make changes (e.g. by using Coda to connect to the server and editing the files). Before committing your changes back to GitHub, you need to set your identity in Git:
git config – global user.email „email@example.com“
git config – global user.name „Your Name“
Access your Node.js app
If you‘re developing a Node.js app, your development server will probably run on port 3000 which is not accessible on the GCP network by default. In order to access the app from your iPad, you need to create a firewall rule in GCP:
Within the GCP console go to VPC Network > Firewall Rules and create a new firewall rule with the following parameters:
- Direction of Traffic: Ingress
- Action on Match: Allow
- Source: 0.0.0.0/0
- Protocols and Ports: tcp:3000
- Target Tag: nodejs-tcp-3000
Of course you need to assign the corresponding network tag (nodejs-tcp-3000) to the VM instance running your development server. Now you should be able to access your Node.js app from your iPad, e.g. by using Safari.
Does it work? Does it make sense?
Well, my conclusion is that yes, it is definitely possible to develop a Node.js app from an iPad. It is, however, not very convenient and in my opinion only makes sense for minor changes or some app maintenance. Here are some limitations that I came across so far and that are really impacting my development productivity on iPad:
- I‘m using the Atom editor when developing on my Mac and I really like to see the lines of code highlighted that changed in comparison to the latest Git commit. Coda is a great code editor for the iPad, but it (obviously) falls short in comparison to full blown editors on the Mac like Atom or VS Code.
- When doing web development, it‘s crucial to have access to an inspection tool like the Chrome DevTools in Google Chrome. To my knowledge, there is no possibility to access a console or inspect the DOM in Safari on iPad.