Niall McMahon

Search by DuckDuckGo

App Deployment


Niall McMahon

Some practical setup for (multi-tenant) app development/deployment using:

Single- vs. Multi-tenant Architecture

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

Single-tenant architecture: everybody gets their own copy of everything; often used in enterprise application development and for desktop software.

   |           |           |
  User        User        User

Multi-tenant architecture: users share the app and database; often used for multi-user online services.

Modern Single-page Application (SPA)

PEAN/PERN Technology Stack

Back End

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

Client Side (Front End)

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!

PostgreSQL Documentation
PostgreSQL: About
PostgreSQL: History


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

dnf is preferred to yum these days.

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

The details of this are here: PostgreSQL Documentation: Installation from Source Code

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.

Once psql starts, type:


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.

See PostgreSQL Documentation: CREATE ROLE

Assign Password to User

To set a password for the new user, type:

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:

CREATE DATABASE new_database;

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

See, PostgreSQL Documentation: Creating a Database

Assign User to Database

You might want to assign the new user to the database; this new user can be the app that you'll write:


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:

PostgreSQL Documentation: Password Authentication
PostgreSQL Documentation: The pg_hba.conf File
PostgreSQL Documentation: Secure TCP/IP Connections with SSH Tunnels

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. This makes development (potentially) a lot easier in a Microsoft-centric organisation.

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.

Psql cheat sheet.

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. See:

Installing Node.js via package manager
How To Install Node.js on Debian 10

Node Package Manager (npm)

Install npm, the Node 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.

Node Version Manager

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.



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 can be other locations also.


Virtual hosts, e.g. and
Security Enhanced Linux.