An old post of mine a friend suggested to re-post it here.
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 siteIf 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
PR
with the changes you wish.
Writing a neat package:
If you are one of those smart lazy devs, you might want to use generator-node. If that is too heavy for you then checkout generator-nm
If you do not want
generators
you can stick withnpm init
and create the required dir structure manually.Make sure your
package.json
is valid, maybe you would need package-json-validatorIf you are new to
npm
you 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
package.json
has afiles
attribute 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.md
looks 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.
Further reading:
I strongly believe in writing one-line node modules, but I wanted to hear the same from @sindresorhus so I asked him a question.
Me and few of my friends (Stoeffel & Tomekwi ) together have put up 1-liners and also checkout npm-scripts
Apart from what I had mentioned for
readme.md
have a look at this template.
Top comments (1)
Understatement maybe?