So far I have authored/contributed around 200+ modules on
npm and they get around
1.5M downloads per month, which is a decent figure; as a part of this I have learnt a few things and I would like to share the same in this post.
Todo before writing a module:
Search npm and look for an already existing module that solves your issue: you could do a
npm search <module>or search from the site
If you find one such good module, do read its code and see if you can improve something, it might be performance, logic or test fixes.
If you find a module and it does not do exactly what you are looking for, then send a
PRwith the changes you wish.
Writing a neat package:
If you do not want
generatorsyou can stick with
npm initand create the required dir structure manually.
Make sure your
package.jsonis valid, maybe you would need package-json-validator
If you are new to
npmyou can use validate-npm-package-name to check if your package name is a valid npm package name.
It would be good if you make sure that your
filesattribute which in turn has a main attribute in it.
Make sure you have test cases in place and also integrate it with continuous build service, like travis.
Make sure your
README.mdlooks good, as it has info about how to install your module, what it does, API docs and a gif, logo is a plus.
Take care while releasing package, using tools like release-it
Getting to the top:
There are many ways to showcase your module so that people will find it and hopefully use it but here are a few good ways to create a useful package:
Dig into GitHub and find a few trending projects, read the source, find code that can be extracted into a module, make a module and send a PR with it, most of time it gets accepted as modularity always wins.
Dig into the most dependent modules of node and repeat the above steps.
If the above did not work in your favour, make your own light weight module that just does a small part of the larger module.
P.S: It's not just about getting to the top, rather it's about doing one thing and doing it the best way.
Apart from what I had mentioned for
readme.mdhave a look at this template.
P.S: Thanks to @nihar108 for typo and grammar fixes.