Edit on GitHub
Report issue
Page history

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

title: Run Meteor on Google App Engine Flexible Environment description: Learn how to deploy a Meteor app to App Engine flexible environment. author: anassri tags: App Engine, Meteor, Node.js date_published: 2016-10-25


Meteor is an open source platform for web, mobile, and desktop.

– meteor.com

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


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


  1. Install Meteor on your local machine.

  2. Create a MongoDB instance as described here. Remember your MONGO_URL, you will need that later. An example MongoDB URI would be mongodb://username:password@host:port.


  1. Initialize a Meteor project by running the following commands:

    meteor create [YOUR_APP_NAME]
    cd [YOUR_APP_NAME]
    meteor add reactive-dict
    meteor remove autopublish

    replacing [YOUR_APP_NAME] with your app name.

  2. To add database functionality, edit [YOUR_APP_NAME]/client/main.js to look like:

    import { Template } from 'meteor/templating';
    import { ReactiveVar } from 'meteor/reactive-var';
    import { Meteor } from 'meteor/meteor'
    import './main.html';
    Template.hello.onCreated(function helloOnCreated() {
      // counter starts at 0
      this.counter = new ReactiveDict({value: '0' });
      var instance = this;
      Meteor.subscribe('counters', function () {
        var counterConn = new Mongo.Collection('counters');
        instance.counterConn = counterConn;
        var counterList = counterConn.find({}).fetch();
        var dbCounter = counterList[0];
        instance.dbCounter = dbCounter;
        instance.counter.set('_id', dbCounter._id);
        instance.counter.set('value', dbCounter.value);
      counter() {
        return Template.instance().counter.get('value');
      'click button'(event, instance) {
        // Increment counter
        instance.counter.set('value', instance.counter.get('value') + 1);
        // Update counter on DB
        instance.counterConn.update(instance.dbCounter._id, {
          '$set': {'value': instance.counter.get('value') }
  3. Edit [APP_NAME]/server/main.js so that it looks like:

    import { Meteor } from 'meteor/meteor';
    import { Mongo } from 'meteor/mongo';
    Meteor.startup(() => {
      // code to run on server at startup
      const Counters = new Mongo.Collection('counters');
      // Make sure a Counter entry exists
      if (Counters.find({}).fetch().length == 0)
        Counters.insert({value: 0})
      // Publish counters
      Meteor.publish('counters', function () {
        return Counters.find({});


  1. Run the app with the following command:

    MONGO_URL=[MONGO_URL] meteor run

    replacing [MONGO_URL] with your MongoDB URI.

  2. Visit http://localhost:3000 to see the Welcome to Meteor! message.

    When you're done, use CTRL-C to exit Meteor.


  1. Add the following to the package.json file:

    "scripts": {
      "cleanup": "rm -rf ../bundle/",
      "dist": "npm run cleanup && meteor build ../ --directory --architecture os.linux.x86_64 --server-only",
      "predeploy": "npm run dist && cp app.yaml ../bundle/ && cp Dockerfile ../bundle/",
      "deploy": "npm run predeploy && (cd ../bundle && gcloud app deploy -q)"

    These scripts provide you with some tasks that prepare the app for deployment to Google App Engine flexible environment. See Custom deployment for more information about custom Meteor deployments.

  2. Configure a custom runtime by running the following command:

    gcloud beta app gen-config --custom
  3. Replace the contents of the Dockerfile file with the following:

    FROM gcr.io/google_appengine/nodejs
    COPY . /app/
    RUN (cd programs/server && npm install --unsafe-perm)
    CMD node main.js

    The custom Dockerfile is required in order to properly build the Meteor app in production.

  4. Add the following to the generated app.yaml file:

      ROOT_URL: https://[YOUR_PROJECT_ID].appspot-preview.com

    replacing [YOUR_PROJECT_ID] with your Google Cloud Platform project ID and [MONGO_URL] with your MongoDB URI.

  5. Run the following command to deploy your app:

    npm run deploy
  6. Visit https://[YOUR_PROJECT_ID].appspot.com to see the Welcome to Meteor! message, replacing [YOUR_PROJECT_ID] with your Google Cloud Platform project ID. To test database functionality, click on the button a few times and refresh the page. You should see your previous button-click count appear after a few seconds.

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

Submit a Tutorial

Share step-by-step guides


Request a Tutorial

Ask for community help


GCP Tutorials

Tutorials published by GCP


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.