A Computer Polyglot, CLI + WEB ♥'r.

Authoring Node Modules

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 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 with npm init and create the required dir structure manually.

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.