You’re probably aware of the
.gitignore file. But what about the less commonly talked about
.npmignore? Turns out there is a small but noteworthy difference between the gitignore and npmignore files.
.npmignore file is mainly used to avoid packaging files in your project that dont need to be downloaded by a client who wants to consume your package. Think of npmignore as the younger brother of gitignore. While using gitignore is the best way to avoid adding unnecessary files to your commit history and thereby your bundled package, npmignore is more permissable and lets you add files to your git repository. But it comes into play when your package is uploaded to npm, ignoring any file patterns listed when uploading the files. Another reason this is so great is because smaller package size means less download time and faster npm installs for a client!
Therefore it safe to consider it a best practice when working with nodejs or any other project that lets you upload to npm to add a
.npmignore file to smaller packages that will be reused elsewhere and use it to list the file patterns that correspond to test files, ci files, docs and examples. Basically, anything about your module that isint really needed by the consuming package is a good candiate to be mentioned in the