DEV Community

Jalu Pujo Rumekso
Jalu Pujo Rumekso

Posted on • Updated on • Originally published at jprumekso.github.io

Introduction to Learn Hapi/MySQL Series

I'm learning Hapi/MySQL now and I thought it would be fun to share what I learned through a series here.

Alos, to make this series even more interesting, fun, and easy to read, I will present it through a story of a person learning HapiJS. The person is Joe — an ambitious man who determined to build a software as a service app.

Disclaimer

Obviously, since I'm still learning it, I am not a Hapi/MySQL expert. So, please do understand that whatever I tell you in this series comes from a fellow learner's perspective, not as a Hapi or MySQL expert.

Prerequisites

In order to be able to follow this series easily, at least you've got Javascript fundamental covered and getting comfortable at using terminal and NPM. Prior experience with Node development or other Node frameworks is beneficial but is not required.

So If you are totally new to Javascript, understand the basics first and come back later.

And technically, you should have the following programs installed:

  • Node
  • NPM
  • MySQL

Alright, I think it's enough for the introduction. Let's start Joe's story.

Background Story

After getting comfortable with writing Javascript for the frontend, Joe decided that he should learn Node backend development too so he could become a full-stack Javascript developer. That way, he can independently create an API to power his frontend app.

Fortunately, Joe already has some familiarity with a particular database, namely MySQL. He learned it a long time ago from a course Intro to SQL: Querying and Managing Data that is available for free at Khan Academy. Yes, he knew that, from his research, the Javascript community actually prefers MongoDB, however, he wants to use his existing knowledge so he could get up and running as soon as possible. So for now, he will stick to MySQL until he finds a good reason to switch to others.

And for the Node framework, he chose HapiJS.

What and Why Hapi?

So what is Hapi and why Joe chose it?

Here is what Joe found in his research.

On Hapi's official site. Joe found these:

  • "The Simple, Secure Framework Developers Trust"
  • "Build powerful, scalable applications, with minimal overhead and full out-of-the-box functionality"
  • "Originally developed to handle Walmart’s Black Friday scale."

"If it's simple then I'll be able to understand it easily. If it's secure then it would save me a lot of trouble on a security matter that I am clueless about. If it's full out-of-the-box functionality then I don't need to deal with much third-party library. And if it can handle Walmart's Black Friday, then surely it can handle my simple app!", John said to himself.

Joe also found these convincing pieces of information from DWYL's Learn Hapi repo:

  • WalmartLabs are the guys who found/solved the Node.js CORE Memory Leak; they have developed Hapi following Benchmark Driven Development and the result is a high-performance framework
  • The Lead Developer of Hapi is Eran Hammer who was one of the original authors of the OAuth (Secure Authentication) Spec. He has built a security-focussed mindset into Hapi and reviews all code included in Hapi. Several members of the Node Security Project are core contributors to Hapi which means there are many security-minded eyes on the code.

So that's Hapi and why Joe chose it.

The Mission

Joe decided that he should build a point of sale app. The reason is that he wanted to modernize his wife's retail store. Until now, the store's transaction was still recorded using pen and paper. For some basic usage, it's pretty convenient. However, when it comes to searching and analyzing the transaction, it's a nightmare!

In order to be useful to power his wife's store digitally, Joe thought that the app should have the following features:

  • Recording sales (obviously)
  • Ability to sell on credit
  • Applying discount
  • Creating multiple stores
  • Tracking inventory
  • Transfer order
  • Purchase order
  • Stock Adjustment
  • Multiple roles: owner & employee

Also, Joe wanted his app to have the following features so he can offer the app to other store owner and make money from it:

  • Offering subscription plan
  • Accepting payment

Then Joe began his research on how to make that kind of app. Soon he realized that the app is not trivial. It requires comprehensive learning of backend development. At least he should be able to do the following tasks to turn his idea into reality:

  • Creating server
  • Defining endpoints of various HTTP methods
  • Handling user request
  • Defining model
  • Working with database
  • Authentication with JWT
  • Authorization

After defining the goals, now Joe is ready to embark on his first journey on learning HapiJS.

Top comments (0)