PM2 Deployment

Follow these instructions to to deploy a Skulljs project with PM2.

Requirements

  • Working project — check that your project works locally
  • Node.js on local computer and remote server — latest LTS version or newer
  • Skulljs-cli on local computer — the version you used to create the project or a newer version
  • PM2 globally installed on the remote server — latest LTS
  • MySQL on remote server — 8.0 version or newer
  • (Optional: HTTPS) An SSL Certificate

Deploy your app

Set up SSL certificate

(Optional) Set up SSL certificate for HTTPS

  1. Put your certificate key in sslcert/xxx.key.pem, you are only able to rename the xxx part.
  2. Put your certificate file in sslcert/xxx.cert.pem, you are only able to rename the xxx part.

Build the project

sk build
  1. Enter the name of the app
  2. Enter the ip address or the name of the remote server where you wish to deploy your application.
  3. Enter the port of the remote server where you wish to deploy your application.
  4. Select which hypertext transfer protocol do you would like to use.
  5. Select PM2 when the CLI prompts you to select a manager

Setup the folder on the remote server

  1. Create a folder with the name of your choice in your server. Ex: my-awesome-app
  2. Copy the dist folder in that folder
  3. Install the dependencies with the following command
npm install

Initialize the database on the remote server

  1. Change the database configuration in the .env file
  2. Init the database

Ex: Prisma

# Classic
npx prisma db push
npx prisma db seed
or
# With migration
npx prisma migrate deploy
npx prisma db seed

Use PM2

The last step of the deployment is to setup PM2. We use PM2 to manage and keep our application online 24/7.

Start an app

In the dist folder, use the following command.

npm run pm2:start

Managing process

You can use the following commands to manage your processes.

npm run pm2:start
npm run pm2:stop
npm run pm2:restart
npm run pm2:reload
npm run pm2:delete
npm run pm2:logs

Go to the app

Well done ! Your app is now deployed and available at:

http(s)://[the name or the ip of the server]:[port of the server]