navd: My first-ever Node.js module

Victor Truong

In an effort to further my knowledge on Node.js, I decided to write a simple Node.js module. This would also be a chance to play around with ES6's syntax (because it's awesome).

Problem

It was just another Sunday of my soon-to-end summer break. I was browsing a Node project when all of a sudden I see something like this:

const app = require("../../app");

In this snippet, it's evident that app.js is in a directory two above that of which it is being required from. Now let's try a more obscure example. In only one glance, try counting how many directories this will go up:

const app = require("../../../../../app");

Compared to the previous example, this one took a bit more time. But that was only five directories. What if someone needed to go up ten? What if they had to require multiple files that from far above? It gets really ugly really quick.

...Ta-da! Instead of having to count how many, you just look at the first parameter of navd.up! Great for code skimmers!

Publishing to npm

This process was actually a lot easier than I thought it would be. There's literally no moderation you have to go through. I was able to claim the package name on npm, so that's mine now.

Final thoughts

This was fun — both for learning and a first. I do plan on continuing development on this and write more modules as I come up with new ideas. Bonus: navd is open-source on GitHub, so if you have any features you think would be a great addition to it, open a new issue there!