Simple, fast, dynamic landing page in Node.JS and Hapi.js

02 Mar 2013

For FrozenRidge.co, our full-stack consulting business, we needed a simple, fast and easy-to-maintain landing page. The requirements were:

  • Templates for re-use of HTML boilerplate across pages.
  • Dynamic server-side code execution to process contact requests.
  • Static file serving for assets.
  • Simple, fast, low-maintenance and low-cost hosting.

Our starting point was actaully 100% static files. We considered using a static website compiler for templates. However, due to the need to handle contact requests, we needed something dynamic.

Node.js

As we already know and love node.js, we decided to build a tiny web application server for our site. We used the following components and services:

Hapi.js

We decided to try Hapi.js instead of the better-known Express (which we also like) because it has in-built validation and JSON marshalling for API endpoints.

Swig Templates

Swig templates are very similar conceptually to Django or Mako templates. Swig supports template inheritance aka blocks, which we wanted.

Contact Form & Sending Email

One of the main purposes of our landing page is to showcase our areas of expertise, and allow potential customers to start a conversation with us as easily as possible.

Our philosophy is to solve hard problems for our customers, with the absolute minimal amount of hassle. The reason you work with FrozenRidge is because we deliver quality results, fast and nonsense-free.

Initially, we simply wanted our contact form to send us nicely-formatted emails. In the future, we might store requests in a database or CRM. But for now, email is good enough.

With Hapi.js and Nodemailer, we wrote an AJAX API endpoint that sends e-mail with server-side validation in just a few lines of code. To reliably send email in the cloud, we use Mailgun. Mailgun is an awesome service and their free plan is quite generous.

Hosting on Nodejitsu

We decided to use Nodejitsu as our web host. A nice property of node.js is that one process can handle quite a bit of traffic. Hence, all we needed to get started was a single cloud-hosted node.js process, and they offer this for only $3/month.

We could have easily used a private server, but using a PaaS provider like Nodejitsu offers the following advantages:

  • Automated deploys.
  • High availability.
  • Scale up to handle more load if needed.
  • Very affordable.

Source

Feel free to use our quick and dirty sourcecode as a starting point for your own Node.JS & Hapi.JS landing page!