Edit on GitHub
Report issue
Page history

Run Hapi.js on App Engine flexible environment

Author(s): @jmdobry ,   Published: 2015-12-17

Contributed by Google employees.

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


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


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

    npm init
  2. Install Hapi.js:

    npm install --save @hapi/hapi


Create a server.js file with the following contents:

    "use strict";

    const Hapi = require("@hapi/hapi");

    const init = async () => {
      const server = Hapi.server({
        port: process.env.PORT || 8080,
        host: ""

        method: "GET",
        path: "/",
        handler: (request, h) => {
          return "Hello World!";

      await server.start();
      console.log("Server running on %s", server.info.uri);

    process.on("unhandledRejection", err => {



  1. Run the app with the following command:

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


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

    runtime: nodejs
    env: flex
  2. Deploy your app:

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

Submit a tutorial

Share step-by-step guides

Submit a tutorial

Request a tutorial

Ask for community help

Submit a request

View tutorials

Search Google Cloud tutorials

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.