Deployment
When you are ready to deploy your application to a remote server, you can follow this guide.
Table of contents
- Step 1 - Install the prerequisities
- Step 2 - Build the project
- Step 3 - Setup the folder on the remote server
- Step 4 - Setup the kestrel-cli file on the remote server
- Step 5 - Initialize the database on the remote server
- Step 6 - Use PM2
- 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
- Select yes when the cli ask you to modify the cors config
- 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
- Create a folder with the name of your choice. Ex: my-awesome-app
- 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)
- Copy the sslcert folder in the folder created in 1
- Replace the files in the sslcert folder with your SSL certificate
- 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
- Make a file in the folder created in the previous step named “kestrel-cli.json”
Step 5 - Initialize the database on the remote server
- Change the prod database configuration in the .env file
- Run the following command
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.
Managing process
You can use the following commands to manage your processes
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.
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]