Skip to main content
Tutorials 4 min read 3 views

The ultimate guide to PostgreSQL, Nginx, and Node.js on Ubuntu 24.04

This guide is for developers and system administrators who need a clear, reliable resource for installing and configuring Node.js, PostgreSQL, and Nginx on Ubuntu 24.04. Following this guide, you will set up a robust development environment for web applications.

H

Hardik Kanajariya

Sep 10, 2025

Share:
The ultimate guide to PostgreSQL, Nginx, and Node.js on Ubuntu 24.04

Ubuntu 24.04 is the latest LTS release, optimized for stability and performance. It features up-to-date repositories for popular developer tools like PostgreSQL 15+, Nginx 1.24+, and Node.js 20+. Combining these technologies creates a solid foundation for modern web applications—from database management to server routing and backend logic.

Explore detailed installation instructions, security setups, and integration tips to run PostgreSQL as your database, Node.js for server-side JavaScript, and Nginx as a powerful reverse proxy and web server.


Installing PostgreSQL on Ubuntu 24.04

PostgreSQL is a powerful open-source relational database known for reliability and advanced features.

Step 1: Update Your System

Start by updating your packages:


sudo apt update && sudo apt upgrade -y

Step 2: Install PostgreSQL and Contrib Package

Install PostgreSQL and additional utilities:


sudo apt install postgresql postgresql-contrib -y

Step 3: Start and Enable PostgreSQL Service

Ensure PostgreSQL runs on system boot:


sudo systemctl start postgresql

sudo systemctl enable postgresql

Step 4: Basic Usage

Switch to the postgres user and access the PostgreSQL shell:


sudo -i -u postgres

psql

From here, create databases and users as needed.

For more on PostgreSQL setup and advanced configuration, check out my detailed blog on Installing and Managing PostgreSQL on Ubuntu.


Installing and Configuring Nginx on Ubuntu 24.04

Nginx is a high-performance web server and reverse proxy, essential for handling web traffic efficiently.

Step 1: Install Nginx


sudo apt install nginx -y

Step 2: Start and Enable Nginx


sudo systemctl start nginx

sudo systemctl enable nginx

Step 3: Basic Configuration for Your Website

Create a server block in /etc/nginx/sites-available/yourdomain.com:


server {

    listen 80;

    server_name yourdomain.com www.yourdomain.com;

    root /var/www/yourdomain.com/html;

    index index.html index.htm;

    location / {

        try_files $uri $uri/ =404;

    }

}

Enable the site and reload Nginx:


sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

Configure SSL with Let’s Encrypt when ready using Certbot.

For advanced Nginx reverse proxy setups, including proxying Node.js apps, see my post on Configuring Nginx as a Reverse Proxy.


Installing Node.js on Ubuntu 24.04

Node.js provides a runtime environment to run JavaScript on the server side, facilitating building backend applications.

Step 1: Install Node.js and npm from Default Repository


sudo apt update

sudo apt install nodejs npm -y

Step 2: Verify Installation


node -v

npm -v

Alternatively, use Node Version Manager (NVM) for flexible version control if your projects require specific Node.js versions.

For more on Node.js installation methods and tips, check my blog on Node.js Setup on Ubuntu 24.04.


Integrating PostgreSQL with Node.js

Use the pg Node.js module to connect your Node.js applications to PostgreSQL databases.

Basic Setup

Install the pg package:


npm install pg

Create a connection in your app:


const { Client } = require('pg');

const client = new Client({

  user: 'your_username',

  host: 'localhost',

  database: 'your_database',

  password: 'your_password',

  port: 5432,

});

client.connect()

  .then(() => console.log('Connected to PostgreSQL'))

  .catch(err => console.error('Connection error', err.stack));

For more detailed guides and CRUD examples, visit PostgreSQL with Node.js Setup and Usage.


Using Nginx as a Reverse Proxy for Node.js

To expose your Node.js app securely and efficiently, configure Nginx as a reverse proxy.

Example configuration in /etc/nginx/sites-available/myapp:


server {

    listen 80;

    server_name yourdomain.com;

    location / {

        proxy_pass http://localhost:3000;

        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;

        proxy_set_header Connection 'upgrade';

        proxy_set_header Host $host;

        proxy_cache_bypass $http_upgrade;

    }

}

Enable and reload Nginx:


sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

Conclusion

Setting up PostgreSQL, Nginx, and Node.js on Ubuntu 24.04 provides a powerful tech stack that is well-suited for modern web development projects. This guide covered installation, basic configuration, and integration tips to help developers build scalable, secure applications.

Explore more about full-stack development and backend technologies in my portfolio blogs such as:

Feel free to dive deeper into each topic through the linked detailed articles for more advanced configurations and tips.


Tags

#PHP #Node.js #MySQL #Best Practices #Tutorial
H

Hardik Kanajariya

Full Stack Developer with expertise in Laravel, Vue.js, and mobile app development. Passionate about creating innovative solutions and sharing knowledge with the developer community.

Comments

Be the first to comment on this post!

Leave a Comment

Your comment will be reviewed before being published.

Stay Updated

Get More Articles Like This

Subscribe to my newsletter and get the latest articles, tutorials, and insights delivered directly to your inbox. No spam, just quality content.

Join 500+ developers who get weekly updates. Unsubscribe anytime.

Ready to Start Your Project?

Let's bring your vision to life with a custom solution that drives results and exceeds expectations.

Fast Delivery
Quality Assured
24/7 Support

Trusted by 6+ clients worldwide

5.0 Rating
100% Success Rate
24h Response