When PM2 detects changes, it will automatically restart the process. Through the -watch- parameter, PM2 will start the application and verify any changes in the directory. You may stop it later by using the "delete" command combined with the same name -pm2test- used above: pm2 delete pm2test To better identify the process in the PM2 list, use the -name- parameter to assign an identifier to your application.įor example, by starting the test application through: pm2 start /var/node/pm2test/index.js -name pm2test Then, proceed by eliminating all the processes present, using the command: pm2 delete all Advanced use of PM2 Through the "list" command, PM2 allows you to view all the currently active processes, their consumption of system resources and much more information. │ 0 │ index │ default │ N/A │ fork │ 6554 │ 0s │ 0 │ online │ 0% │ 25.7mb │ root │ disabled │ │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │ If everything works correctly, the process just started should be seen by using the command: pm2 list ![]() Once completed, start your application using the "start" command: pm2 start /var/node/pm2test/index.js To use it throughout the system, and not just in your application, use the "-g" parameter to perform a global installation: npm install pm2 -g Stop the script from running by using the CTRL + C key combination. Save the file you just created and check its operation: node index.js Recall the function above every second Insert the following instructions into the file: function writeToLogFile()] - Alive` ) Using a text editor of your choice, create an "index.js" file: nano index.js To test the functionality of PM2, prepare a simple application that prints the current date on the console so that the execution of your software can be verified over time.īut first, create a directory where to save the application: then proceed using the following commands: mkdir /var/node/pm2test -pĮnter the newly created directory: cd /var/node/pm2test Verify the installation, asking for the version installed: node -v If it is not on your system, install the latest stable version of Node.Js using the following commands: curl -sL | sudo bash. In case of a local server, go to the next step and open the terminal of your server. If you haven't done so yet, following our guide is recommended to connect securely with the SSH protocol. ![]() To get started, connect to your server via an SSH connection. After creating a small sample application with Node.Js, you will learn how to start it, stop it, and how to properly manage its log files. ![]() In this guide you will see how to install and best configure PM2. PM2 is a process manager that can run Node.js applications as daemons within the system, restarting the applications in the event of a crash.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |