Creating a RESTful API with HapiJS and NodeJS and MYSQL

In this post we have explained about how to create a RESTful API with HapiJS and NodeJS and MYSQL. Many web applications they provide API to access their data via RESTful.  This process is called as web services. We have implemented RESTFUL API using NodeJS with MYSQL Database using Hapi JS web services.


– You have to install NodeJs latest version.
– MYSQL Database.
– Install hapi.js package.
– Install JOI package.
– Install Encryption package.
– POSTMAN chrome extension.

Step 1:

Create a sample “users” table in your localhost

Step 2:  

Setup Node Restful Project

Go to Terminal or Command Line, create a project folder.

Step 3: 

Initialize your node project, this will create a package.json file.

Step 4: 

Install hapi.js plugin for Restful APIs.

Step 5: 

Create a Node Server

Step 6:

Run Project

Open your browser and launch the following URL, you will find “welcome” result.

Step 7:

Install MYSQL Database Connection

Step 8:

Update mysql connecton in server.js file.

Step 9:

Get Users List



Step 10:

Validate user inputs so install JOI

Step 11:

Get particular user information 



Step 11:

We need to encrypt the user password, bcryptjs package will provide you the salt encryption code.

Step 12:

User POST form



Step 13:

Delete a user

Thanks for reading this post. If You have any queries and please post your comments below box.




I’m Blogger and Programming Blog, Tutorials, PHP, MySQL, jQuery, Laravel, Wordpress and Codeigniter