Setup script for NodeJS apps using PM2 and PostgreSQL as a database.
- Enable PM2 for your app (See Digital Ocean Community)
pm2 start hello.js
pm2 startup systemd
systemctl status pm2
# Other commands
pm2 stop appname
pm2 restart appname
pm2 list
- Enable SSL for your app (See Digital Ocean Community)
sudo apt-get install letsencrypt
sudo systemctl stop nginx
sudo letsencrypt certonly --standalone
# Certs now available in /etc/letsencrypt/your_domain_name/
- Setup a database for your app (See Digital Ocean Community)
# Log in as postgres user
sudo -i -u postgres
# Access db
psql
# Make new user
createuser --interactive # or when not logged in as postgres:
sudo -u postgres createuser --interactive
#create db from within postgres user
createdb yourapp
# When handling sensitive stuff on the command line
rm ~/.psql_history
#One way of making a user with a database
sudo adduser app
sudo su - postgres
psql
CREATE USER app WITH PASSWORD 'password';
CREATE DATABASE app OWNER app;