For running Node.js applications in production, you need process manager who takes care of the node processes.
We explain how to use the PM2 for setting up a Node.js Application for production on this site.
PM2 is a daemon process manager that will help you manage and keep your application online.
ssh john-doe@instance-ip-address
cd htdocs/www.domain.com/
npm install pm2@latest -g
Use the following command to start your application via pm2:
pm2 start npm --name $app-name -- start
Your application is now running via pm2.
To save the pm2 configuration, execute the save command:
pm2 save
To ensure, that your application is running after a reboot of your instance, you need to configure a cron job.
echo $PATH
/home/john-doe/.nvm/versions/node/v14.19.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
crontab -e
PATH=$PASTE_THE_OUTPUT_OF_$PATH @reboot pm2 resurrect &> /dev/null
Example configuration
pm2 status
The status should be online to confirm that your Application is running after reboot.
PM2 provides a logs command to see the application’s output, which helps troubleshoot.
pm2 logs
dploy is a powerful code deployment solution that simplifies releasing new application versions.
dploy allows developers to automate the deployment process and ensure their applications are always up-to-date and running smoothly. Whether deploying a small website or a complex web application, dploy makes it easy.
On this site, you find a guide to install and configure Ghost on CloudPanel.
You can create a Node.js Site with the following command as root user if you like the command line.
clpctl site:add:nodejs --domainName=www.domain.com --nodejsVersion=16 --appPort=2368 --siteUser='john-doe' --siteUserPassword='!secretPassword!'
Create a Database and copy the Database Name, Database User Name, Database User Password.
Log in via SSH with the Site User:
ssh john-doe@server-ip-address
npm install ghost-cli@latest -g
ghost install --db mysql --port 2368 \ --dbhost 127.0.0.1 \ --dbuser $DATABASE_USER_NAME \ --dbpass $DATABASE_USER_PASSWORD \ --dbname $DATABASE_NAME \ --process local \ --no-setup-linux-user \ --no-setup-ssl \ --no-setup-nginx \ --dir /home/$SITE_USER/htdocs/$DOMAIN/
Ghost needs to be started after an instance reboot. We will create a script that gets executed after the reboot.
ssh john-doe@server-ip-address
mkdir ~/scripts/
nano ~/scripts/ghost-start.sh
Modify the –dir value and save the start script:
#!/bin/bash export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm ghost start --dir $HOME/htdocs/ghost.moby.io/ --no-setup-linux-user > $HOME/logs/ghost.log &
chmod 700 ~/scripts/ghost-start.sh
crontab -e
@reboot /home/$SITE_USER/scripts/ghost-start.sh &> /dev/null
On this site, you find a guide to install and configure Strapi 4 on CloudPanel.
You can create a Node.js Site with the following command as root user if you like the command line.
clpctl site:add:nodejs --domainName=www.domain.com --nodejsVersion=14 --appPort=1337 --siteUser='john-doe' --siteUserPassword='!secretPassword!'
ssh john-doe@server-ip-address
cd htdocs && rm -rf www.domain.com
npx create-strapi-app@latest www.domain.com
To build the Admin Panel, go to the root directory of your strapi installation
cd htdocs/www.domain.com/
and execute npm run build with NODE_ENV=production:
NODE_ENV=production npm run build
To run Strapi, go to the root directory of your strapi installation
cd htdocs/www.domain.com/
and execute npm start with NODE_ENV=production:
NODE_ENV=production npm start
The output will look like this:
To create a user, you can now open your Strapi Installation in the browser https://www.domain.com/admin.
For running Strapi in production, it’s essential to have an process manager like pm2 who takes care of the node processes.
Follow the Node.js Deployment for a step-by-step guide.