Hosting n8n for Free with Railway
by Alex Hyett |  6 min read
 Published: 30 January 2023
 Updated: 19 April 2023
I have been using n8n for a couple of months now, and it has allowed me to automate so much of my daily workflow.
These are some of the automations I now have set up with n8n:
- When a new blog post is published with Strapi,
- Update my content calendar when I publish a new video on YouTube
- Schedule tweets to Twitter at the most optimum times
- Sync my want to read books on Goodreads to an Airtable
If I were to code all of these automations myself, it would have taken more than a couple of weeks to set up each one, once you take account of infrastructure and everything else.
What is n8n?
If you haven’t heard of n8n, it is IFTTT and Zapier on steroids. It has all the same integrations as the main platforms, but also lets you call custom APIs as well write your own code to do more complicated things.
No-code tools are useful, but when you combine that with a little bit of code as well, they become incredibly powerful.
🚀 Are you looking to level up your engineering career?
You might like my free weekly newsletter, The Curious Engineer, where I give career advice and tackle complex engineering topics.
📨 Don’t miss out on this week’s issue
They might not be the best solution to do things at scale, that is where custom solutions really shine, but for automating your daily workflow they are incredibly useful.
Running n8n
There are a number of options for running n8n, and they all have their own pros and cons.
Desktop Application
You can run n8n as a desktop application. This is great if you just want to try out the tool and see what you can build with it.
If you plan to run any workflows that deal with files, then you will probably need to run the desktop application.
The downside is that any workflows that you need to run on a schedule or be triggered by an external action aren’t going to work unless you leave your computer on all the time.
Cloud Host
N8n offer their own cloud option, however unless you have a lot of automations running for your business it is hard to justify the cost.
The starter plan is slightly more expensive than Zapier, but both platforms only allow you 20 workflows at around ÂŁ20 a month, which seems a bit steep.
Self-Host Locally
If you have your own home server such as a Raspberry Pi or something similar, you can run n8n using Docker.
I have my own n8n running on my home server which I use for my personal automations such as backing up my Goodreads list.
If you are using Traefik as a reverse proxy you can use the following Docker compose file to set up your own instance.
You will also need to set up .env
 file to contain all of your environment variables like this one:
Assuming that your home server is called servername
 then this will make n8n available on http://servername/n8n
.
Self-hosting locally is useful, but if you don’t have your own server or have an unreliable internet connection, then there is a better option.
Hosting with Railway
I recently discovered Railway as hosting platform. For developers and individual use, they give you $5 of credit every month.
This is enough to cover the cost of running n8n in most cases. Obviously, if you have hundreds of workflows running all the time, it is going to use more resources.
With Railway, you are only charged for what you use, so if your instance is just running idle most of the time it isn’t going to use many resources.
Railway make it really easy to set up services using their templates. The template for n8n can be found on GitHub, and there is a button to Deploy to Railway in the readme.
If that doesn’t work, you can select New Project in Railway and search for n8n. It should come up with template.
Enter the details and click deploy. This will kick off the build of the project.
After a few minutes, n8n will be deployed and Railway will show you the URL for your instance. It will look something like this https://n8n-production-837d.up.railway.app
.
If you want to add your own domain, you can do that as well by going to the Settings tab and adding your own custom domain.
Once added, you need to set up the corresponding CNAME record on your domain.
There are a few more environment variables we also need to set up before we are done. This can be done on the variables tab.
N8N_ENCRYPTION_KEY
 - If you don’t set your own encryption key, then n8n will generate a new one each time it is deployed. Which means it won’t be able to read any of the credentials that have been stored.N8N_HOST
 - Set this to your domain. Either the custom one you have set up or the one you have been given, e.g.Ân8n-production-837d.up.railway.app
N8N_PROTOCOL
 - Set this toÂhttps
WEBHOOK_URL
 - If you want to trigger any of your workflows using a webhook, then it is important to set this. For some reason for me, it didn’t set it to the n8n host e.g.Âhttps://n8n-production-837d.up.railway.app
Once these have been set, Railway will deploy again and then your instance is ready to use.