hapi — Become a Better Developer in 2017

For us developers is an unwritten law to educate ourselves and keep track of new tools and technologies. It’s essential to continuously learn and make personal progress. You don’t want to be that guy who’s stuck in the 90’s with tools that are outdated since years!

The hapi framework has an awesome ecosystem and great developers that spend a lot of their spare time contributing on hapi and associated plugins. Now is the best time to reflect and decide on what to improve in 2017. This article comprises the (for us) important aspects to advance in your personal development when working with hapi or generally Node.js.

hapi Series Overview

Use ES2015

The hapi framework itself and plugins filed under the hapijs GitHub organization are already updated to use ES2015 and you should do that as well. With the release of Node.js v4 the ES2015 support was at 57% and you needed transpilers (like Babel) or polyfills to fully benefit from features that are not yet available. With the release of Node.js v6, the ES2015 support grew to 99% and there’s no excuse to not use the newly available capabilities in your development with hapi.

More details on ES2015 support in Node.js are available at node.green.

Use Latest Node.js LTS

The hapi community is blazing fast in making the modules compatible with the latest Node.js LTS. Weeks before v6 was declared LTS, all hapi projects were v6-ready and you could leverage the benefits immediately at release.

Make sure your own plugins and code bases are ready for upcoming Node.js releases to allow yourself and other developers to advance and use new technologies.

Support (And Use) Promises

Every developer should be open to new coding paradigms and the Node.js community is split-head between callback fanatics and promise aficionados and async/await early birds. There’s no right or wrong, use what you prefer!

As a module or plugin developer, allow your users to benefit from promises as well. It’s some kind of overhead to support promises additionally to callbacks, so play the long game and it will definitely pay off. Read more about callback and promise support in Node.js modules.

Due to hapi’s powerful plugin system, there’s no immediate benefit of supporting promises and callbacks. However, don’t wrap your mind just around callbacks, be open to support promises when they make sense.

Use Plugins to Develop Your App

As a hapi developer, you know that the plugin system is the core of all good! It’s a best-practice to use plugins extending the framework to add your desired functionality.

Unraveling your project’s code base and put functionality into separated plugins will take some time. Of course it’s nasty work, because you’re in your comfort zone of just using your application as it is. Give yourself the time to think about your project and the possibilities to isolate functionality into a plugin.

Do you use utility functionality over and over in your route handlers? Why not create a plugin that decorates the request interface and provides the functionality in your route handlers.

Review your code base, structure and architecture. Plan to use plugins to provide the individual functionality and in the long run: benefit from separated concerns and a much better setup. And you can easily reuse the plugins in other projects, too!

Don’t Reinvent the Wheel

I know that we as developers tend to solve problems on our own. We don’t like to rely on code that solves a problem but isn’t formatted the way we want it to be. We don’t like to use the implementation of others because there’s a missing option that is required in our use case. We need to write it ourselves to get it right!

In those situations, remind yourself to take a deep breath. Is it worth to spend the development time and effort to reimplement the functionality again so that it matches our preferred formatting and options? In almost every scenario, we should spend our time otherwise and not solving already solved problems. Extend the existing solution if necessary. Else: take it and win.

Use a Coding Style

Every developer has its own coding style and a preferred style guide in mind. Especially when working with a team, you should agree on a coding style like the hapi coding conventions or the JavaScriptStandard Style or whatever style you and your team prefer. Put some time into researching available styles or just agree on a custom one. Tools like EditorConfig help you to create and maintain a coding style with support for a lot IDEs.

Use an Error Tracking Service/System

At Future Studio, we’ve added error tracking just in September 2016 and fell immediately in love with it. We chose Sentry and are very happy with their platform and service. It’s a great tool! And besides all the local testing of your application, there are various scenarios that you can’t test during development.

For example, with the launch of the Future Studio University we’ve added the Braintree integration for payment handling. Know what? During development, everything was smooth and we fixed all bugs and tested various scenarios. As soon as the first student enrolled, we got a webhook notification from Braintree and a typo just crashed the flow to send a welcome email. It was just a little typo … and we wouldn’t have known about that issue without an error tracking platform.

We highly recommend to integrate such a system sooner than later. It’s definitely worth the effort! Just to name a few: Sentry, Rollbar, Bugsnag, Raygun, Airbrake. There are many more, just decide for one. You can’t go wrong.

Be Open to Give and Not Just Take: Engage in the Community

As a hapi developer, you’re facing and fighting many personal battles with the framework and plugins. You gain a lot expertise in specific functionalities of hapi and its ecosystem. Share your knowledge with the community. Take some minutes every day to answer issues on GitHub about hapi and plugins.

It will help us grow as a group of developers and keeps the feeling of an inclusive team. Share your tips and tricks in your personal blog or on twitter. The @hapijs user on twitter is ready to share your thoughts with all the followers. Take a step forward.

Solve the Most Simplest Problem First

It’s easier said than done. Usually you think in large problems and want to solve it all at once. Or even better, just come up with the best and sexiest solution at your first try. You know, that’s an illusion and there’s always a better way to solve the problem.

Especially with complex problems, it’s hard to wrap your mind around the actual problem and to keep all the details in mind that you need to keep an eye on. How to solve that? Break your large problem into multiple smaller ones. In such small problems, solve the little nasty details. Ultimately, compose all the small pieces to solve the large problem. Of course you need to glue your small solutions together to result in a solution for the complex problem. But that’s the easy road to success.

Become a Better hapi Developer in 2017

Now is the best time to reflect yourself and plan for 2017. Take actions on the points from above where you identify the most. Improve on those and become the developer you want to be.

Just to remind you of possible actions to take:

  • Use ES2015
  • Use Latest Node.js LTS
  • Support (And Use) Promises
  • Use Plugins to Develop Your App
  • Don’t Reinvent the Wheel
  • Use a Coding Style
  • Use an Error Tracking Service/System
  • Be Open to Give and Not Just Take: Engage in the Community
  • Solve the Most Simplest Problem First

Give yourself accountability by sharing your actions in the comments below or tweet us @futurestud_io. Do you have further aspects and tools for 2017 where you what you want to improve? Please share it with us :)

Make it rock in 2017!

Explore the Library

Find interesting tutorials and solutions for your problems.