Wednesday, 27 August 2025

Why PM2 Is Not Launching Your Node.js App—and How to Fix It

Why PM2 Is Not Launching Your Node.js App—and How to Fix It

Broken Your Node.js PM2 — and How to Fix It

Have you ever faced the frustration of manually running your Node.js app only for it to work perfectly—and yet, when launching it via PM2, it stubbornly refuses to respond? This is a surprisingly common issue, but fortunately, one that can often be resolved with a systematic approach.

In modern production environments, PM2 is a trusted manager for running Node.js processes reliably. But when things go wrong, it can feel like a black box—your app shows as “online” yet fails to respond. This blog will walk you through the most frequent culprits, structured troubleshooting steps, and production-level hardening tips to ensure your app stays up and running smoothly.

Common Reasons PM2 Fails to Launch Your Node Process

  • Script Path or Filename Errors: A misconfigured script path may lead to silent failures. Verify file references like server/index.js.
  • Application Not Listening on the Expected Port: Ensure your app is binding and listening on the correct port.
  • Daemon Mode & Execution Context (Especially on Windows): GUI apps may not launch correctly without the --no-daemon flag.
  • Missing System Startup Configuration: Without running pm2 startup and enabling systemd, apps won’t auto-start on reboot.
  • Node Version Mismatch: After Node upgrades (e.g., via NVM), reinstall and update PM2 to maintain compatibility.
  • Cluster Mode Port Conflicts: Avoid EADDRINUSE errors by assigning unique ports or using fork mode.

Step-by-Step Troubleshooting Guide

  1. Verify Script Path & Logging
    Use pm2 logs and pm2 show <app> to inspect the app’s status and confirm the script path.
  2. Confirm App is Listening on the Correct Port
    Use netstat, lsof, or curl to ensure the app binds to the expected port.
  3. Use --no-daemon if Needed
    Launch with pm2 start app.js --no-daemon on systems that require GUI compatibility.
  4. Configure System Startup Properly
    Run:
    pm2 startup
    # Follow systemd instructions
    pm2 save
  5. Reinstall PM2 After Node Updates
    After switching Node versions, reinstall PM2 and run pm2 update.
  6. Avoid Port Conflicts in Cluster Mode
    Assign unique ports or switch to fork mode to prevent errors.

Best Practices for Production Stability

  • Use ecosystem.config.js to define mode, port, memory limits, and restart policies.
  • Implement logging and health checks using --watch, --max-memory-restart, and structured formats.
  • Integrate monitoring tools like ELK, Better Stack, or CloudWatch.
  • Ensure proper handling of unhandled promise rejections to avoid silent crashes.

FAQs

  • Why does PM2 say my app is “online,” but it’s not responsive?
    Likely due to incorrect port binding or silent failure in the startup routine.
  • How do I make PM2 launch my app after reboot?
    Use pm2 startup followed by pm2 save to persist processes.
  • Why won’t my GUI Node app start with PM2?
    Try --no-daemon or start via npm scripts.
  • What should I do after upgrading Node?
    Reinstall PM2 and run pm2 update to sync versions.

Conclusion

When PM2 isn’t launching your Node.js app, the root cause is usually in environment or configuration. Use this guide to diagnose script path errors, port issues, version mismatches, and system startup configs. With proper setup, PM2 becomes an indispensable tool for Node.js app stability.

Monday, 11 August 2025

Reconnect Magic Mouse Without a Cable: The Quick Keyboard Shortcut Method

 


If you’ve ever had your Apple Magic Mouse suddenly disconnect while working, you know the frustration—especially if you don’t have a Lightning cable handy. For many Mac users, reconnecting without a mouse feels impossible. But here’s the good news: you can reconnect your Magic Mouse without a cable using a quick keyboard shortcut method.

This guide will show you how to navigate macOS entirely from your keyboard, restore your Bluetooth connection in seconds, and keep your workflow moving—no desk rummaging or cable hunts required.


Why This Shortcut Works

macOS includes built-in features that let you control your Mac entirely with the keyboard, including accessing system tools like Bluetooth File Exchange. By combining these with accessibility settings, you can quickly re-pair your Magic Mouse when it drops the connection.

This method is:

  • Cable-free – no need for a Lightning cable.

  • Fast – reconnect in under a minute.

  • Practical – works anywhere, even if you have no spare peripherals.





Step-by-Step Keyboard Method

Step 1: Launch Bluetooth File Exchange

  • Press Command (⌘) + Space to open Spotlight.

  • Type Bluetooth File Exchange and hit Return.

  • If Bluetooth is off, macOS will prompt you to turn it on—press Return again to confirm.

Step 2: Prepare Your Magic Mouse

  • Flip the switch on the bottom of the mouse to turn it off and on again, putting it in pairing mode.

Step 3: Navigate to Bluetooth Settings

  • Press Command (⌘) + Space, type Bluetooth, and hit Return.

  • Use arrow keys to select your Magic Mouse from the device list, then press Return to connect.


Alternate Method via System Preferences

If the above doesn’t work, try this:

  1. Command (⌘) + Space, type Mouse, and hit Return.

  2. Enable Full Keyboard Access with Option + Command + F5.

  3. Use Tab to move focus to “Set Up Bluetooth Device,” then press Space to open pairing options.

  4. Select your Magic Mouse and press Return.


Bonus Tips for a Seamless Experience

  • Enable Full Keyboard Access permanently in System Settings > Accessibility > Keyboard to make navigation easier.

  • Reset Bluetooth module by holding Shift + Option while clicking the Bluetooth icon in the menu bar and choosing “Reset Bluetooth Module.”

  • If your mouse doesn’t appear, delete Bluetooth preferences (/Library/Preferences/com.apple.Bluetooth.plist) and restart.


Why This is a Game-Changer for Mac Users

This method saves you from downtime, keeps your workspace cable-free, and makes you less dependent on extra accessories. Whether you’re in a cafĂ©, on a flight, or just working from a couch, you can keep your workflow running without missing a beat.


FAQs

Q: How do I reconnect a Magic Mouse without a cable?
A: Use Spotlight (Command + Space) to open Bluetooth File Exchange, turn on Bluetooth, then pair your Magic Mouse from Bluetooth settings.

Q: What if my Magic Mouse doesn’t show up in Bluetooth settings?
A: Restart Bluetooth, toggle your mouse off/on, reset the Bluetooth module, or delete Bluetooth preference files.

Q: Can I do this on older Macs?
A: Yes, as long as you have Spotlight search and Bluetooth File Exchange installed (macOS Lion and later).



Conclusion

Losing your mouse connection doesn’t have to stop your productivity. With this quick keyboard method, you can reconnect your Apple Magic Mouse without a cable in under a minute—no stress, no slowdown. Try it next time and share this tip with fellow Mac users who might need it.


Why PM2 Is Not Launching Your Node.js App—and How to Fix It

Why PM2 Is Not Launching Your Node.js App—and How to Fix It Broken Your Node.js PM2 — and How to Fix It Have you ever...