Powered By GitBook
run-expressjs-on-google-app-engine
Learn how to deploy an Express.js app to App Engine flexible environment.
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.

Prerequisites

    1.
    Create a project in the Cloud Console.
    2.
    Enable billing for your project.
    3.
    Install the Cloud SDK.
    4.
    Install Node.js on your local machine.

Prepare

    1.
    Initialize a package.json file with the following command:
    1
    npm init
    Copied!
    2.
    Add a start script to your package.json file:
    1
    "scripts": {
    2
    "start": "node index.js"
    3
    }
    Copied!
    3.
    Install Express.js:
    1
    npm install --save express
    Copied!

Create

Create an index.js file with the following contents:
1
const express = require('express');
2
const app = express();
3
​
4
app.get('/', (req, res) => {
5
res.send('Hello World!');
6
});
7
​
8
const server = app.listen(8080, () => {
9
const host = server.address().address;
10
const port = server.address().port;
11
​
12
console.log(`Example app listening at http://${host}:${port}`);
13
});
Copied!

Run

    1.
    Run the app with the following command:
    1
    npm start
    Copied!
    2.
    Visit http://localhost:8080 to see the Hello World! message.

Deploy

    1.
    Create an app.yaml file with the following contents:
    1
    runtime: nodejs
    2
    env: flex
    Copied!
    2.
    Run the following command to deploy your app:
    1
    gcloud app deploy
    Copied!
    3.
    Visit http://YOUR_PROJECT_ID.appspot.com to see the Hello World! message.
Last modified 7mo ago