Petros Kyriakoupersonal blog

I am a full stack web developer. Love tinkering all the time, especially anything javascript related.

PM2 will eat your hard disk - How to avoid

July 10, 2019

If you ever used PM2 in production or anywhere where its left unattended you might think all is good and dandy but appearances can be deceiving. I found out the hard way that PM2 can suck your hard disk dry. Purely because the logs keep writing and writing and when you have half a dozen microservices logging stuff every minute it can quickly add up to hard disk space.


So how do you deal with this? First and foremost pm2 provides a command called flush, so use that first to delete all logs pm2 flush.

Next to avoid this issue completely, lets use a pm2 addon call pm2-logrotate. Its a classic log rotate mechanism which deletes past log message after passing a certain threshold i.e after passing 10mb in size.

Installing pm2-logrotate

PM2 makes it really easy to add addons - all you have to do is run the following:

pm2 install pm2-logrotate

and you are done. Feel free to explore configuration options here


PM2 is a really great process manager but you have to be aware of its little quirks before going in production.

Note to self: logging can be a real pain in the *rse if left unattended.