Powered By GitBook
run-koajs-on-google-app-engine
Learn how to deploy a Koa.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.

Prepare

    1.
    Initialize a package.json file with the following command:
    1
    npm init
    Copied!
    2.
    Install Koa.js:
    1
    npm install --save koa
    Copied!

Create

Create a server.js file with the following contents:
1
const Koa = require('koa');
2
const app = new Koa();
3
​
4
app.use((ctx) => {
5
ctx.body = 'Hello World!';
6
});
7
​
8
app.listen(process.env.PORT || 8080);
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 6mo ago