Link Search Menu Expand Document (external link)

Deployment

When you are ready to deploy your application to a remote server, you can follow this guide.


Table of contents

  1. Step 1 - Install the prerequisities
  2. Step 2 - Build the project
  3. Step 3 - Setup the folder on the remote server
  4. Step 4 - Setup the kestrel-cli file on the remote server
  5. Step 5 - Initialize the database on the remote server
  6. Step 6 - Use PM2
    1. Start an app
    2. Managing process
    3. Setup startup script
  7. Step 7 - Go to the app

Step 1 - Install the prerequisities

  • Verify that your project work in development
  • Latest LTS of Node.js on the remote server and on the local computer
  • Nodemon globally installed on the remote server and on the local computer
  • kestrel-cli globally installed on the remote server and on the local computer
  • Any kind of database on the remote server (use the same as you used in development is a plus)
  • PM2 installed on the remote server
  • An SSL Certificate

Step 2 - Build the project

$ kc build
  1. Select yes when the cli ask you to modify the cors config
  2. Enter the ip or the name of the remote server which you want to deploy your app

Step 3 - Setup the folder on the remote server

  1. Create a folder with the name of your choice. Ex: my-awesome-app
  2. Copy the dist folder in that folder. (you can remove the node_modules folder and reinstall the modules after the copy if you want the process to be faster)
  3. Copy the sslcert folder in the folder created in 1
  4. Replace the files in the sslcert folder with your SSL certificate
  5. Verify that the path in server.js correctly refer to the files in the sslcert folder

Step 4 - Setup the kestrel-cli file on the remote server

  1. Make a file in the folder created in the previous step named “kestrel-cli.json”
{
  "projects" : {
    "backend_path" : "dist",
    "frontend_path" : "dist"
  },
  "version" : "3.0.0"
}

Step 5 - Initialize the database on the remote server

  1. Change the prod database configuration in the .env file
  2. Run the following command
$ kc idb

You can now test your app by typing using npm start in the dist folder. The URL is https://[the name or the ip of the server].

Step 6 - 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.

$ pm2 start src/server.js --name <name of the app>

Managing process

You can use the following commands to manage your processes

$ pm2 restart <name of the app>
$ pm2 reload <name of the app>
$ pm2 stop <name of the app>
$ pm2 delete <name of the app>
$ pm2 list
$ pm2 logs

Setup startup script

This step will allow you to restart PM2 with the processes it manage when the server boot/reboot.

You can use the following commands for that.

$ pm2 startup
$ pm2 save

Step 7 - Go to the app

Well done ! Your app is now deployed and available at https://[the name or the ip of the server]