You'll want to make sure you have NodeJS installed on your computer. Then, setup is as simple as:
npx add-gitignore
If you've got an older version of node that doesn't yet have npx, here's a more traditional setup:
npm i -g add-gitignore
add-gitignore macOS Emacs node# or whatever you need
Alternatively, running just add-gitignore gives you a nice multi-select interface from which you can choose what to ignore, and using the --help flag helps you out.