Edit on GitHub
Report issue
Page history

Author(s): @{[ username ]}  Published: {[ TutorialCtrl.tutorial.date_published | date:'mediumDate' ]}

title: Run Hapi.js on Google App Engine Flexible Environment description: Learn how to deploy a Hapi.js app to Google App Engine flexible environment. author: jmdobry tags: App Engine, Hapi.js, Node.js date_published: 2015-12-17


Hapi.js

Hapi is a rich framework for building applications and services. Hapi enables developers to focus on writing reusable application logic instead of spending time building infrastructure.

– hapijs.com

You can check out Node.js and Google Cloud Platform to get an overview of Node.js itself and learn ways to run Node.js apps on Google Cloud Platform.

Prerequisites

  1. Create a project in the Google Cloud Platform Console.
  2. Enable billing for your project.
  3. Install the Google Cloud SDK.

Prepare

  1. Initialize a package.json file with the following command:

    npm init
    
  2. Install Hapi.js:

    npm install --save hapi
    

Create

Create a server.js file with the following contents:

const Hapi = require('hapi');

// Create a server with a host and port
const server = new Hapi.Server();
server.connection({
  host: '0.0.0.0',
  port: process.env.PORT || 8080
});

server.route({
  method: 'GET',
  path:'/',
  handler: (request, reply) => {
    reply('Hello World!');
  }
});

server.start(() => {
  console.log('Server running at:', server.info.uri);
});

Run

  1. Run the app with the following command:

    npm start
    
  2. Visit http://localhost:8080 to see the Hello World! message.

Deploy

  1. Create an app.yaml file with the following contents:

    runtime: nodejs
    env: flex
    
  2. Run the following command to deploy your app:

    gcloud app deploy
    
  3. Visit http://YOUR_PROJECT_ID.appspot.com to see the Hello World! message.

See more by @{[ username ]} and more tagged {[ tag ]}{[ $last ? '' : ', ' ]}

Submit a Tutorial

Share step-by-step guides

SUBMIT A TUTORIAL

Request a Tutorial

Ask for community help

SUBMIT A REQUEST

GCP Tutorials

Tutorials published by GCP

VIEW TUTORIALS

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates.