Authoring node modules

hemanth.hm - Aug 31 '18 - - Dev Community

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 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.

  • Make sure your package.json is valid, maybe you would need package-json-validator

  • If 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 a files 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.

  • Use badges like: nodei, david et.al

  • 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:

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .