DEV Community

Amandeep Singh
Amandeep Singh Subscriber

Posted on

The Ultimate Guide to Self-Hosting n8n for Free using Render and Nhost

Are you tired of manual, repetitive tasks? Do you wish you had a powerful, open-source automation tool that you could truly own and control?

Then welcome to the world of n8n!

n8n workflow

N8n is a powerful, open-source, and feature-rich workflow automation tool. With its intuitive visual editor and a wide array of over 400 integrations, it's a stellar alternative to SaaS giants like Zapier and Make. But where should you run it? That's the first question on every developer's mind.

The Hosting Dilemma

Every journey with n8n begins with a choice: do you opt for the convenience of a managed cloud service or do you take the road of self-hosting? This is the central hosting dilemma.

  1. n8n Cloud: This is the easiest, most hassle-free option for those who want to get started quickly and don't want to worry about server maintenance. Updates, security patches, backups, and scaling are all handled for you. However, n8n's cloud plan can start around $24/month for a limited number of executions, with costs quickly climbing for higher usage, which can be a significant barrier for students and hobbyists.

  2. Self-Hosting: Self-hosting means you install and run n8n on your own infrastructure, giving you complete control over your data, a key advantage for organizations with strict data privacy requirements. You can easily accomplish this with Docker, which offers portability, reproducibility, and simplified updates. However, this comes with the responsibility of managing the server, including security, backups, and updates.

  3. The Best of Both Worlds: The Solution: This article proposes a middle ground that combines the flexibility and cost-effectiveness of self-hosting with the simplified management of a cloud platform. By using a managed service like Render for application hosting and Nhost for a free PostgreSQL database, you can bypass many of the complexities of traditional self-hosting.

Cloud Hosting Providers Comparison

For those who choose the self-hosting path, selecting the right cloud provider is a critical decision. While a traditional VPS (Virtual Private Server) from a company like DigitalOcean offers a high degree of control, platforms like Render and Railway have emerged as strong contenders with their simplified, managed services.

Here’s a comparison of these providers to help you decide.

Provider Starting Price Specs Included Notes
Render $0/month + DB 0.5 vCPU, 512 MB RAM (Web) Free web service, but spins down after 15 mins of inactivity. The database is a separate, paid service starting at $7/month.
Railway $5/month (Hobby plan) ~$5 in usage credit; pay for usage Usage-based pricing can be hard to predict but avoids over-provisioning.
DigitalOcean ~$6/month (Droplet) 1 vCPU, 2 GB RAM, 25–50 GB SSD Polished UI, but requires manual setup and management.
Sliplane €9/month 2 GB RAM, 2 vCPU, 40 GB SSD Offers one-click n8n deployment with backups and HTTPS.
Hetzner ~€3.79/month 2 vCPU, 4 GB RAM, 40 GB SSD (CX22) Requires a lot of technical know-how. You are responsible for all management, including SSL and backups.

For this tutorial, we will focus on Render and Nhost because they offer a powerful, zero-cost entry point for a fully functional, self-hosted n8n instance.

The Backend: Why a PostgreSQL Database is a Must

While n8n can function with a default SQLite database, a production-level, self-hosted deployment requires a more robust solution. This is where PostgreSQL comes in as the recommended choice for your backend database.

SQLite: By default, n8n uses SQLite, which is a file-based database. It's excellent for local development and single-user scenarios because of its simplicity. However, it is not designed for concurrent write operations, which makes it unsuitable for a cloud environment where multiple processes might access it at the same time.

PostgreSQL: Switching to a client-server database like PostgreSQL unlocks a new level of performance, reliability, and scalability.

  • Concurrency and Reliability: PostgreSQL is a highly reliable and fault-tolerant database that uses Multi-Version Concurrency Control (MVCC) to handle multiple users accessing data simultaneously without conflicts.
  • Scalability: PostgreSQL can handle a significant quantity of data and a large number of concurrent users, making it ideal for growing applications.
  • Data Integrity and Security: PostgreSQL is ACID-compliant (Atomicity, Consistency, Isolation, and Durability), which ensures that database transactions are processed reliably and data integrity is maintained.
  • Managed Services: By using a managed PostgreSQL service like Nhost, you are freed from the burden of database administration, including tasks like optimization and backup management.

Step-by-Step Deployment Guide

This tutorial will walk you through the step-by-step process of deploying your own self-hosted n8n instance on Render, using a managed PostgreSQL database from Nhost.

1. Set Up Your Nhost Database

First, you need to set up your database on Nhost.

  1. Sign up and Create a Project: Sign up for Nhost using your GitHub account or email. Once in the dashboard, click "Create Project" and give it a name.
  2. Configure Database and Get Credentials:
    • Navigate to your project's settings, then go to the "Database" section.
    • Here you need to enable Public access to Connect directly to the Postgres database.
    • Here, you will find the connection information for your PostgreSQL database.
    • Crucial Step: Note down all the individual components from the connection string: the host, port, user, password, and database name. You will need to parse the single DATABASE_URL into these separate environment variables for Render.
    • Change the password for your database and save it securely.

Nhost database credentials screen

Deploy n8n on Render

Next, you will deploy the n8n application to Render, connecting it to your Nhost database.

  • Sign Up for Render: If you don't have an account, sign up for Render.
  • Create a New Web Service: From the Render dashboard, click "+ New" and select "Web Service".

Render dashboard with 'New Web Service' selected

  • Choose the Docker Image:
    • Under "Source," select "Existing Image".
    • In the "Image URL" field, enter n8nio/n8n:latest and click "Connect". This will use the official n8n Docker image.
    • Give your service a name, choose a region closest to you, and select the "Free" instance type.

Image n8n docker

Render configuration screen for a new web service

  • Add Environment Variables: This is the most important step for connecting your n8n app to the Nhost database and configuring it properly.

    • Expand the "Advanced" section and add the following environment variables.
    • DB_TYPE: postgresdb
    • DB_POSTGRESDB_DATABASE: <nhost database name>
    • DB_POSTGRESDB_HOST: <nhost postgres host>
    • DB_POSTGRESDB_PASSWORD: <nhost postgres password>
    • DB_POSTGRESDB_PORT: 5432
    • DB_POSTGRESDB_USER: postgres
    • DATABASE_URL: <nhost connection string> + ?sslmode=require. E.g. postgres://postgres:<password>@<host>:<port>/<name>?sslmode=require
    • GENERIC_TIMEZONE: America/New_York
    • N8N_ENCRYPTION_KEY: LTZl8zNn721OB3x73nGS1QNKu9mXoqblHw0LFr9ifq4= (This is a unique key for encrypting credentials in your database. For security, you must generate your own!)
    • N8N_HOST: This will be the URL that Render assigns to your service. You will add this after the first deployment. E.g. self-hosted-n8n.onrender.com
    • N8N_PORT: 5678
    • N8N_PROTOCOL: https
    • WEBHOOK_URL: <render web service URL> This will also be the Render URL, added after the first deployment. E.g. https://self-hosted-n8n.onrender.com/
    • TZ: America/New_York
    • NODE_ENV: production
    • N8N_RUNNERS_ENABLED: true
    • N8N_PAYLOAD_SIZE_MAX: 16
    • N8N_LOG_LEVEL: info
    • N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: false

  • Initial Deployment: Click "Create Web Service" to start the deployment.

3. Final Configuration and Verification

After the initial deployment, you need to update the two environment variables and verify everything is working.

  1. Update URLs: Once your service is live, Render will provide a public URL (e.g., self-hosted-n8n.onrender.com). Go to your service's settings, then "Environment," and click "Edit". Replace the placeholder values for N8N_HOST with your new Render URL and WEBHOOK_URL with your Render URL including https://.
  2. Check Logs: After the redeployment, check the logs on the Render dashboard. A successful deployment will show lines like "Starting migration," "Finished migration," and "n8n ready on ::, port 5678".
  3. Verify Functionality: Visit the Render URL to access your n8n instance and create your first user account. Your cloud-hosted n8n is now ready to use, and all your workflows and data will be persisted in your Nhost PostgreSQL database.

First Workflow & Verification

At first, it may take a few minutes for the container to download the n8n image and spin up the service, especially for the first-time deployment. Also, note that Render's free web services will "sleep" after 15 minutes of inactivity and will take some time to wake up when accessed again. This is normal for the free tier and a small price to pay for a free, managed service.

After signing up wiht email and password start creating your own workflows and credentials, which are now safely stored and secured in the cloud and remotely accessible. You have unlocked all the features available by hosting it on the cloud, such as making your workflows public.

Final Thoughts & Next Steps

well done

Congratulations! You have successfully deployed your own n8n instance with a robust PostgreSQL backend for little to no cost. This powerful setup gives you the freedom and control of self-hosting, combined with the convenience of a managed cloud environment. Now, go build something amazing!

Bonus

List of some awesome n8n workflows

Top comments (0)