How to add a specific file to Firewall Exceptions list?
I don't have enough rep to comment, so I'll attempt an answer...

I wanted to comment since I'd like to clarify why you need to add npm - my install of npm (via homebrew) works OK, without poking a hole in the firewall. Obviously YMMV...! But be aware I've not properly tested this with npm (I tested adding npm, and it continued to work fine.)

I believe you want the application layer firewall. (It's the same firewall you can also access through System Preferences -> Security &amp; Privacy -> Firewall).

My socketfilterfw's API appears to have changed from the one discussed in the linked article. I'd suggest caution, and that you check what the API is for your version before doing anything else:

/usr/libexec/ApplicationFirewall/socketfilterfw -h


My version of socketfilterfw doesn't have the "-t" option mentioned in the linked article so I had to use:

/usr/libexec/ApplicationFirewall/socketfilterfw --add /usr/local/bin/npm