I did some reading on the hapi framework for quickly making full stack applications. From what I have gathered it is a little more full featured out of the box compared to express, so I thought I would give it a try. As such this will be a sort of getting started, and first impressions kind of post. When I first wrote this post I was using hapi 16.x which it would seem is still being supported in 2019, as I can see the occasional bug fix and so forth in the github repo of the project.
Most of the documentation including the official documentation with hapi as of this writing at least is on hapi 17.x. In this section I will be covering a very basic hello world example for hapi 17.x.
For versions of hapi thar are greater than 16.x you will now want to install hapi via @hapi/hapi rather than just simply hapi. So setting up a new hapi js project with hapi 17.x+ might look something like this:
Here is a hapi 17.x hello world server.js file.
Call Hapi.server to create a new server, and then use the server.route to create a route for the root path.
First off this version of hapi is now more or less deprecated, it looks like there is still some support going on, but if you are looking to start a new project with hapi js it might be best to start with hapi 17.x. Still I will leave this section up for the hell of it.
As with starting any node project I start my making a test folder that will contain a package.json file, a .gitignore file, and all the other files that will compose the test project.
In this post I will keep things simple, and just start with a very simple hello world project. So I just need to have hapi itself installed for now.
Now that I have hapi installed in my projects folders node_modules folder I will want to have a server.js file which I will start from the command line. For me it looks like this:
Now I just start the server from the command line, and open localhost:3000 in my browser and it looks like I might just be starting out with something great.
So there is a great deal more to cover, such as how to start up a simple static server, and how to handle some posts rather than just a get request. But so far I am loving hapi, and not just because of the name. Glancing over the api docs on the site, it looks like it is a whole world richer than the more minimalist express framework.
So this is just my getting started post for what will be a line of posts on hapi, because this is the kind of thing that you do not just write one post about. Looks like I will be writing a whole lot on this one because there is a great deal to cover on it. I will hack over this post as more content comes along.