---
title: Install New Relic Node.js agent in GAE flexible environment
source: https://docs.newrelic.com/docs/apm/agents/nodejs-agent/hosting-services/install-new-relic-nodejs-agent-gae-flexible-environment
---

With New Relic's [Node.js agent](https://docs.newrelic.com/docs/agents/nodejs-agent/getting-started/introduction-new-relic-nodejs), you can monitor applications that reside in the [Google App Engine (GAE) flexible environment](https://cloud.google.com/appengine/docs/flexible/nodejs/). Adding New Relic to your GAE flex app gives you insight into the health and performance of your app and extends GAE with metrics you can view in [APM](https://docs.newrelic.com/docs/apm/new-relic-apm/getting-started/introduction-new-relic-apm) and [browser monitoring](https://docs.newrelic.com/docs/browser/new-relic-browser/getting-started/introduction-new-relic-browser).

This document explains how to add New Relic to your GAE flex app using either of these methods:

-   Google App Engine's ["native mode"](https://docs.newrelic.com/docs/accounts-partnerships/partnerships/google-cloud-platform-gcp/google-app-engine-environment#native-mode) installation with a standard GAE runtime
-   Docker installation using a [custom runtime](https://cloud.google.com/appengine/docs/flexible/custom-runtimes/about-custom-runtimes)

## Use native deploy [#native-mode]

To use Google App Engine's ["native mode"](https://docs.newrelic.com/docs/accounts-partnerships/partnerships/google-cloud-platform-gcp/google-app-engine-environment#native-mode) installation with your Node.js app:

1.  Follow standard procedures to [install New Relic's Node.js agent](https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/install-nodejs-agent), including your license key. Be sure to save the `newrelic` module to the `package.json` file.
2.  Follow [Google App Engine procedures for Node.js](https://cloud.google.com/appengine/docs/flexible/nodejs/quickstart) to create a new Cloud Platform project, create an App Engine application, and complete other prerequisites for the [Google Cloud SDK](https://cloud.google.com/sdk/gcloud/).
3.  Optional: Set environment variables to configure the Node.js agent's [GAE `app.yaml` file](https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml).
4.  Use the Google Cloud SDK's `gcloud` command line tool to deploy GAE apps. To deploy your Node.js app to your [initialized GAE flexible environment](https://cloud.google.com/sdk/docs/initializing), run the following command:

    ```bash
    gcloud --project new-relic-apm-nodejs app deploy
    ```

Google App Engine automatically includes your Node.js app's `newrelic.js` configuration file in the deployed package. Wait until the deployment completes, then view your GAE flex app data in the [APM **Summary** page](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/apm-overview-page).

## Build a custom runtime [#build-runtime]

See [Google's documentation for building custom runtimes](https://cloud.google.com/appengine/docs/flexible/custom-runtimes/build). This example describes how to add New Relic to your GAE flex app by building a custom runtime for Docker. You can deploy the app without any special configuration.

For more information about deploying and configuring your Node.js app in the GAE flexible environment, see:

-   [Google App Engine's documentation](https://cloud.google.com/appengine/docs/flexible/nodejs/) for Node.js
-   [Google App Engine's tutorial](https://cloud.google.com/community/tutorials/run-expressjs-on-google-app-engine) to deploy a Node.js app

**1. Set up the GAE project and install dependencies**

1.  Follow standard procedures to [install New Relic's Node.js agent](https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/install-nodejs-agent), including your license key. Be sure to save the `newrelic` module to the `package.json` file.
2.  Follow [Google App Engine procedures for Node.js](https://cloud.google.com/appengine/docs/flexible/nodejs/quickstart) to create a new Cloud Platform project, create an App Engine application, and complete other prerequisites for the [Google Cloud SDK](https://cloud.google.com/sdk/gcloud/).

    The Google Cloud SDK provides the `gcloud` command line tool to manage and deploy GAE apps.

**2. Configure your app.yaml**

The `app.yaml` configuration file is required for a GAE flexible environment app with a custom runtime. At a minimum, make sure it contains:

````yml
runtime: custom
env: flex
```

Optional: Set environment variables.

````

**3. Configure and deploy**

The [Dockerfile](http://docs.docker.com/engine/reference/builder/) defines the Docker image to be built and is required for a GAE flexible environment app.

1.  To create the Dockerfile, build the container, and deploy your app, follow the [GAE procedures for Node.js](https://cloud.google.com/appengine/docs/flexible/nodejs/run-flex-app-on-gke).
2.  Wait until the deployment completes.
3.  To view your GAE flex app data in New Relic, go to the [APM **Summary** page](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/apm-overview-page).

## Optional: Disable health checks [#health-checks]

Google App Engine sends [periodic health check requests](https://cloud.google.com/appengine/docs/flexible/go/configuring-your-app-with-app-yaml#health_checks) to confirm that an instance has been successfully deployed, and to check that a running instance maintains a healthy status. A health check is an HTTP request to the URL `/_ah/health`.

If you create a custom runtime, your app must be able to handle a large number of health check requests. Otherwise, your app data may not display correctly in APM.

If you notice performance issues, disable GAE health checks. In your `app.yaml`, add:

```yml
health_check:
  enable_health_check: False
```

## Get New Relic agent troubleshooting logs from GAE [#agent-logs]

Use these resources to troubleshoot your GAE flex environment app:

-   To connect to the GAE instance and start a shell in the Docker container running your code, see [Debugging an instance](https://cloud.google.com/appengine/docs/flexible/go/debugging-an-instance).
-   To redirect New Relic Node.js agent logs to [Stackdriver](http://cloud.google.com/logging/docs/view/logs_viewer_v2) in the [Cloud Platform Console](https://cloud.google.com/compute/docs/console), change the `newrelic.js` configuration file to:

    ```yml
    log_file_name: STDOUT
    ```
-   To view the logs, use the [Cloud Platform Console's Log Viewer](https://cloud.google.com/appengine/docs/flexible/php/writing-application-logs).
