Hints for diagnosing memory leaks in NodeJS

A couple of things I keep having to rediscover when diagnosing crashes in Node programs caused by running out of memory:

  • Set --max-old-space-size=100 (or some other smallish number of megabytes) to make the crash happen faster and reduce the chance of it bringing down other things on the system.
  • Set --heapsnapshot-near-heap-limit=1 to generate a *.heapsnapshot file when the runtime thinks it’s close to running out of memory. This process takes a long time and a lot of memory of its own (seemingly roughly twice the heap size, more or less), so setting max-old-space-size to something relatively small seems mandatory when using this option, to avoid the snapshot process itself running out of memory.
  • The resulting profile can be loaded in the Chrome developer tools’ Memory tab for viewing.

Gulp was devoured!

If you get this message when you run gulp, you have installed devour which also provides a gulp executable that wraps Gulp and prints this message.

I was having problems building some assets for a project, and eventually discovered this after a lot of hair-tearing trying to figure out why nothing was building. Hopefully the search engines will pick up on this and give more useful results to the next person who has this problem.

How to install NodeJS on Debian/Ubuntu systems using Ansible

Since I've had to figure out how to do this twice now, and the NodeSource instructions make this more confusing than it ought to be. Make sure you replace node_6.x with the appropriate version from the installation instructions and xenial with the results of lsb_release -s -c.

- name: NodeSource package key
  apt_key:
    state: present
    url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
- name: NodeSource repository
  apt_repository:
    repo: 'deb https://deb.nodesource.com/node_6.x xenial main'
- name: Install NodeJS
  apt:
    state: present
    name: nodejs

Using Airbrake with Electron

Just a quick tip on how to use Airbrake to report errors in an Electron renderer process.

Read more »