Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

What is an npmignore file and what is it used for

You’re prob­a­bly aware of the .gitignore file. But what about the less com­monly talked about .npmignore? Turns out there is a small but note­wor­thy dif­fer­ence between the git­ig­nore and npmignore files.

The .npmignore file is mainly used to avoid pack­ag­ing files in your project that dont need to be down­loaded by a client who wants to con­sume your pack­age. Think of npmignore as the younger brother of git­ig­nore. While using git­ig­nore is the best way to avoid adding unnec­es­sary files to your com­mit his­tory and thereby your bun­dled pack­age, npmignore is more per­miss­able and lets you add files to your git repos­i­tory. But it comes into play when your pack­age is uploaded to npm, ignor­ing any file pat­terns listed when upload­ing the files. Another rea­son this is so great is because smaller pack­age size means less down­load time and faster npm installs for a client!

There­fore it safe to con­sider it a best prac­tice when work­ing with nodejs or any other project that lets you upload to npm to add a .npmignore file to smaller pack­ages that will be reused else­where and use it to list the file pat­terns that cor­re­spond to test files, ci files, docs and exam­ples. Basi­cally, any­thing about your mod­ule that isint really needed by the con­sum­ing pack­age is a good can­di­ate to be men­tioned in the .npmignore file.


Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.