Somewhat recently I reduced the size of the virtual machine in which I host this blog. It is quite short on memory, but for the price I pay, can’t really complain.

Just now I was looking on memory usage on the machine, and noticed ps reporting over 100MB being help by npm:

andre@webserver ~]$ ps aux --sort -rss
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
ghost      247  0.0 23.2 1328872 117468 ?      Sl   Jun06   2:58 node index.js
ghost      199  0.0  7.5 1031804 37868 ?       Ssl  Jun06   0:00 npm
root       152  0.0  3.5  77340 17868 ?        Ss   Jun06   0:08 systemd-journald

As you can see, only about 38 MB is actually in RAM (RSS), the rest (VSZ) is either shared libs or in the swap. As you can see by the relative memory usage, I don’t have that much, so why not free those forty megabytes that are not really necessary?

I was starting Ghost by calling npm start --production, which simply calls node on the index.js file. Easy enough to update my systemd service file:

--- a/ghost.service
+++ b/ghost.service
@@ -5,7 +5,8 @@ After=network.target
 [Service]
 WorkingDirectory=/var/www/ghost
 Environment=GHOST_NODE_VERSION_CHECK=false
-ExecStart=/usr/bin/npm start --production
+Environment=NODE_ENV=production
+ExecStart=/usr/bin/node /var/www/ghost/index.js
 User=ghost
 Restart=always
 RestartSec=10