Running whatsapp-web.js on Fly.io

I had some troubles running whatsapp-web.js@1.23.0 here so I might as well share how I solved things.

  • Make sure your machine has at least 1024MB of RAM otherwise OOM kills will be common: fly scale memory 1024 -a APP_NAME.
  • Create a 1GB volume for your machine and mount it (I’ve mounted mine at /data).
  • Use LocalAuth strategy.
  • Use fly logs -a APP_NAME to see the QR Code.

The major pain was LocalAuth. I tried LocalAuth({ dataPath: '/data/whatsapp-data' }) where /data was were my volume was mounted but it simply ignored therefor every time my machine restarted or I deploy it I had to do the QR Code again. So I did this to fix:

  1. Setup the QR code once.
  2. fly ssh console -a APP_NAME then check that your app folder contains a whatsapp-data folder: mv whatsapp-data /data/whatsapp-data so you persist it
  3. Change your dockerfile like this:
--- a/Dockerfile
+++ b/Dockerfile
@@ -42,4 +42,4 @@ COPY --from=build /app /app
 # Start the server by default, this can be overwritten at runtime
 EXPOSE 3000
 ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/chromium"
-CMD [ "npm", "run", "start" ]
+CMD [ "./prod_start.sh" ]
  1. Create a prod_start.sh file on your root.
ln -s /data/whatsapp-data /app/whatsapp-data
npm start
  1. chmod +x prod_start.sh

  2. fly deploy

You don’t need to do the QR Code anymore

1 Like

FYI, this can be done via:

npx @flydotio/dockerfile --cmd="./prod_start.sh"

The advantage of doing it this way is that your change will be remembered and reapplied should you rerun @flydotio/dockerfile later to pick up changes in your application, or even changes in your bun/node/yarn version.

1 Like