Niall McMahon

Search by DuckDuckGo

App Deployment


Some draft notes for multi-tenant app development and deployment using PostgreSQL, Node.js and Express or Apache.

Be sure to check the latest version of the appropriate documentation if things go wrong - these notes were made using some now out-of-date versions of software.

Single- vs. Multi-Tenant Architecture

Database    Database    Database
   |           |           |
  App         App         App
  ___         ___         ___
   |           |           |
  User        User        User

In a single-tenant architecture, everybody gets their own copy of everything; it's often used in enterprise application development and for desktop software.

   |           |           |
  User        User        User

With multi-tenant architecture, users share the app and database; this is most often used for multi-user online services.

Modern Single-page Application (SPA)

PEAN/PERN Technology Stack

modern full-stack application architecture

Back End

Running on one (or more) Linux server(s), perhaps virtual machines.

Front End (Client Side)

Server Setup

Install and configure:

Development Machine Tools



From About PostgreSQL:

PostgreSQL has earned a strong reputation for its proven architecture, reliability, data integrity, robust feature set, extensibility, and the dedication of the open source community behind the software to consistently deliver performant and innovative solutions.
In addition to being free and open source, PostgreSQL is highly extensible. For example, you can define your own data types, build out custom functions, even write code from different programming languages without recompiling your database!

You can find more information at:


In Debian-based systems, use apt-get:

$ sudo apt install postgresql-server postgresql

As a note, apt is preferred to apt-get these days.

In Red Hat derived systems, use yum or dnf:

$ sudo dnf install postgresql-server postgresql

In the same way, dnf is preferred to yum these days.

The process is a little different if PostgreSQL already exists - you'd want to back-up the database contents and configuration first.

The details of this - which worked for Version 9.0 - are at

Create User

To create a new user, type:

$ sudo -u postgres psql

This starts psql, a terminal-based front end for PostgreSQL using the default postgres user (-u).

You ought to see the psql prompt:


At the prompt, type:

postgres=# CREATE ROLE new_user NOINHERIT LOGIN;

This creates a new PostgreSQL user called new_user ; this user can log in to the database and does not inherit any default privileges, i.e. these must be specified explicitly.


Assign Password to User

To set a password for the new user, type:

postgres=# ALTER USER new_user WITH PASSWORD 'aweakpassword';

This assigns the password aweakpassword to the user new_user. If no password is set, the user will be unable to log in.

Create Database

The next step is to create a new database; type:

postgres=# CREATE DATABASE new_database;

This creates a new database called new_database; this database name might be a bit confusing in real life.


Assign User to Database

You might want to assign the new user to the database; this new user can be the app:

postgres=# GRANT ALL PRIVILEGES ON DATABASE new_database TO new_user;

This gives new_user full access to the database, new_database.


When the password is set, PostgreSQL checks the postgresql.conf file for the password_encryption field. This should be set to scram-sha-256, i.e.

password_encryption = 'scram-sha-256'

In addition, the authentication methods specification in the pg_hba.conf file should also specify scram-sha-256, i.e.

host all new_user scram-sha-256

Some precautions:

See also:

Management and Development

pgAdmin is a tool you'll need; it makes PostgreSQL database management a lot easier with a nice GUI and lots of useful functionality.


MS Windows

PostgreSQL and pgAdmin can both run happily on Windows. Creating databases and users can be carried out using pgAdmin. Command line is possible but takes a little more set up.

For more, see:

psql Syntax

As a note, psql commands do not have to be uppercase!

Both uppercase and lowercase work.

I've been using uppercase for clarity.

You can find a psql cheat sheet at

Node.js and Express


In Debian-based systems, use apt as usual:

$ sudo apt install nodejs

In Red Hat derived systems, use yum or dnf:

$ sudo dnf install nodejs

Debian and Red Hat include a version of Node.js in its default repositories.

If you want to install a different version, the process is slightly different.


Node Package Manager (npm)

Install npm, the Node.js package manager using:

$ sudo apt install npm

This allows you to install useful packages for Node.js. You can find out more at

Node Version Manager (nvm)

It's also possible to install the Node Version Manager first and then use this to install and maintain your Node.js installation.


Check Installation

Check that Node.js is installed by typing:

$ node --version

Initialise App

Assuming that Node.js and npm are correctly installed:

$ mkdir myapp
$ cd myapp
$ npm init

You will be prompted for the main app .js file, e.g. app.js.

Install Express

You can install Express with:

$ npm install express --save

The --save flag adds Express to dependency list of app.js.


Install Packages

For example:

Express Server

const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
  res.send('Hello World!')
app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)


Do not run a Node.js / Express server as root if at all possible. If you start the process as root, use setuid to drop the permissions once Node.js has started.

You can start the node application using:
node app.js

Nodemon is a useful package, adding auto restart for node servers.


Mozilla has a nice summary of Node.js/Express.



In Debian-based systems, use apt as usual:

$ sudo apt install apache2
$ sudo service apache2 start

In Red Hat derived systems, use yum or dnf:

$ sudo dnf install httpd
$ sudo systemctl enable httpd
$ sudo systemctl start httpd

Check Installation

In Debian derived systems:

$ sudo service apache2 status

In Red Hat derived systems:

$ sudo systemctl status httpd


To stop Apache:

$ sudo systemctl stop httpd

To start Apache:

$ sudo systemctl start httpd

To stop and then start:

$ sudo systemctl restart httpd

Reload configuration changes:

$ sudo systemctl reload httpd

To stop Apache from restarting automatically on boot:

$ sudo systemctl disable httpd

To re-enable automatic start-up:

$ sudo systemctl enable httpd

Apache will serve files located in the Document Root. This is usually:


But it can be other locations also.


Apache can be configured to handle many situations. For example, to set up virtual hosts, to deal with Security Enhanced Linux and firewalls. You can find out more at

Front End Solutions

The app front end can be a custom written Javascript application served by Apache, or any web server, that makes calls to the back end application built using the tools described. More typically, developers use a front end framework. These include React, Angular, Vue.js and many others. Each has its advantages and disadvantages. More about this some other time.


Each of these tools is an area of specialisation; it takes time to build up the expertise and processes. Nevertheless, it's possible to get a basic full-stack application up and running in a short time.

This page was last rendered on June 29, 2023.