Simple retro guestbook app with steps how to deploy it to production server with automatic TLS (HTTPS).
npm run dev
Create a new server with a provider such as:
- Linode/Akamai
- Digital Ocean
- Hetzner
- etc.
What do we need to install?
- Git (to clone the repository)
- Node.js (runtime)
- Caddy (web server with automatic TLS)
Use NodeSource to install Node.js.
After test if it works:
node --version
cd /opt
git clone https://github.com/rostislavjadavan/guestbook-app
cd guestbook-app
npm install
Note: Don't forget to create .env
file with database credentials.
For process management we will use PM2 (https://pm2.keymetrics.io/docs/usage/quick-start/).
To make application persistent we need to:
# Generate startup script
npm run pm2:init
# Start the application
npm run pm2:start
# Save the process list
npm run pm2:save
More information: https://pm2.keymetrics.io/docs/usage/startup/
Edit /etc/caddy/Caddyfile
:
example.com {
tls email@example.com
reverse_proxy localhost:3000
}
To check for errors you can use caddy validate
command.
Note: Replace example.com
with your actual domain name and [email protected]
with your email address. Your email address will be used as a contact for the certificate provider, Let's Encrypt (https://letsencrypt.org/).
Don't forget to restart Caddy after editing the config file:
systemctl restart caddy
After restart it should automatically obtain TLS certificate and serve the application. If not check the logs via journalctl -u caddy
.
Create new database at https://neon.tech/
CREATE TABLE messages (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
message TEXT NOT NULL,
timestamp TIMESTAMP DEFAULT current_timestamp
);