Powered By GitBook
run-restifyjs-on-google-app-engine
Learn how to deploy a Restify.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 Restify.js:
    1
    npm install --save restify
    Copied!

Create

Create a server.js file with the following contents:
1
const restify = require('restify');
2
​
3
const server = restify.createServer({
4
name: 'appengine-restify',
5
version: '1.0.0'
6
});
7
​
8
server.use(restify.plugins.acceptParser(server.acceptable));
9
server.use(restify.plugins.queryParser());
10
server.use(restify.plugins.bodyParser());
11
​
12
server.get('/', (req, res) => {
13
res.send('Hello World!');
14
});
15
​
16
server.listen(process.env.PORT || 8080, () => {
17
console.log(`${server.name} listening at ${server.url}`);
18
});
Copied!

Run

    1.
    Run the app with the following command:
    1
    node server.js
    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.
    Go to http://YOUR_PROJECT_ID.appspot.com to see the Hello World! message.
Last modified 6mo ago