Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9086

GCPのすゝめ【Google App Engine編】

$
0
0

概要

Google App Engineを使う際の手順とまとめです。

公式ドキュメント
- Google App Engine Node.js スタンダード環境のドキュメント

準備

Google Cloud SDK

projectの作成

# 新しいプロジェクトを作成。$ gcloud projects create [YOUR_PROJECT_ID] --set-as-default# プロジェクトが作成されたことを確認。$ gcloud projects describe [YOUR_PROJECT_ID]
# プロジェクトで App Engine アプリを初期化し、そのリージョンを選択。$ gcloud app create --project=[YOUR_PROJECT_ID]

ディレクトリー構成

.├── app.yaml
├── index.js
├── package-lock.json
└── package.json

アプリケーションの作成

$ mkdir<project name>
$ cd<project name>
$ npm init
$ npm install express
index.js
constexpress=require("express");constapp=express();app.get("/",(req,res)=>{res.status(200).send("Hello, world!").end();});// Start the serverconstPORT=process.env.PORT||8080;app.listen(PORT,()=>{console.log(`App listening on port ${PORT}`);console.log("Press Ctrl+C to quit.");});module.exports=app;

以下を追加

package.json
{..."scripts":{"start":"node index.js",...},...}

GAEの設定

app.yaml
runtime:nodejs10

ローカル環境での起動

起動

$ npm run start

http://localhost:8080/

停止
Ctrl+C

デプロイ

# App Engine にデプロイします。$ gcloud app deploy
# サービスをデプロイして表示$ gcloud app browse

※プロジェクトの課金の有効化や使用するAPIが有効になっていなくてデプロイに失敗することがあります。
とっても簡単ですのでその際はログにしたがって設定をしていってください。

連携できるGoogle Cloud サービス

ストレージ

キャッシュ

ユーザー認証

アナリティクス

感想

firebaseやCloudRun同様にとっても簡単にアプリケーションを公開できました。
今回使用したスタンダード環境では無料枠があるので、ちょっとしたアプリを公開する際にも料金が発生しづらいのが嬉しいポイントですね!


Viewing all articles
Browse latest Browse all 9086

Latest Images

Trending Articles