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
- Put your certificate key in sslcert/xxx.key.pem, you are only able to rename the xxx part.
- Put your certificate file in sslcert/xxx.cert.pem, you are only able to rename the xxx part.
Build the project
sk build
- Enter the name of the app
- Enter the ip address or the name of the remote server where you wish to deploy your application.We recommend to enter the name rather than the ip address to make sure you don’t encounter problems with certificates.
- Enter the port of the remote server where you wish to deploy your application.
- Select which hypertext transfer protocol do you would like to use.Selecting HTTPS requires you to make the optional step. This is recommended.
- Select PM2 when the CLI prompts you to select a manager
Setup the folder on the remote server
- Create a folder with the name of your choice in your server. Ex: my-awesome-app
- Copy the dist folder in that folder
- Install the dependencies with the following command
npm install
Initialize the database on the remote server
- Change the database configuration in the .env file
- Init the databaseActions may vary depending on the ORM being used. Please see below for examples.
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]