Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Google Datastore Blog Application (demo)

License

NotificationsYou must be signed in to change notification settings

sebelga/google-datastore-blog-app

Repository files navigation

A Node.js demo application built with@google-cloud/datastore &gstore-node running on Google App Engine.

This small application shows you how to usegstore-node to build an application on Google App Enginestandard environment.gstore-node is a modeling library that lets you defineSchemas for your entities to easily validate their data before saving them in Google Datastore. It has also other useful features like pre & postmiddleware,virtual properties or acache layer to speed up entities fetching.

Tutorial

I wrotea multi-part tutorial on Medium that goes through the code in this repository. You canfint it here

Highlights

  • Validate entity data before saving it to the Dastore
  • Middleware (deleting a post will delete its feature image & its comments entities)
  • EntitiesCache (memory LRU)
  • Upload/delete image to theGoogle Storage

Running application

You can see a live version of the application at the following url:https://blog-nodejs.appspot.com/blog.
Play with it as much as you want but don't feel sad if your curated post disappears as a Cron job cleans up the posts every 24h 😄.

Getting started

System tools

Before starting make sure that you have the necesary dependencies installed on your system.

  • node (8 +) & npm
  • Google SDK (you candownload it here) with thegcloud cli on your $PATH

Once you have installed the Google SDK, make sure that you areauthenticated. In your terminal run

gcloud auth application-default login

A window browser should open, allowing you to authenticate the Google Cloud SDK.

Google Cloud project

Before starting, create a projet in the Google Cloud Platform to deploy the application.
Go to App Engine and create a new project if you don't have one.

You then have to make sure to:

  1. Enable billing for the project (Enable billing)

  2. Enable the Google Cloud Datastore API (Enable the API)

  3. Set the project asdefault in gcloud

gcloud configset project<your-project-id>

NPM dependencies

Once you have your project configured in Google Cloud, install the application dependencies with

npm install# oryarn

Environment variables

The application needs a few environment variables to be defined. Forlocal development those variables are defined in a.env file. Rename theexample.env file to.env. Make sure to define theGOOGLE_CLOUD_PROJECT andGCLOUD_BUCKET variables. This.env filesould not be commited and pushed to source control.

# -------------------# Server# -------------------## Server port (optional. Default 8080)PORT=3000# -------------------# Google Cloud# -------------------GOOGLE_CLOUD_PROJECT=<your-google-cloud-project>GCLOUD_BUCKET=<your-google-storage-bucket>## Namespace for the Datastore entities (optional)DATASTORE_NAMESPACE=development## Local Datastore Emulator Host (optional but recommended for development)# DATASTORE_EMULATOR_HOST=localhost:8081# -------------------# Misc# -------------------## Enable Logger (optional. Default "true")LOGGER_ENABLED=true## Logger level (optional. Default "info")## Allowed values: 'error', 'warn', 'info', 'verbose', 'debug', 'silly'LOGGER_LEVEL=info

Update the Datastore indexes

To be able to execute the Datastore Queries of this application, you will need first toupdate the Datastore indexes with the command below. For more information about indexes,read the documentation.

gcloud datastore create-indexes ./index.yaml

Start the Application in local

npmstart-local

You can now navigate tohttp://localhost:3000 and start creating posts and comments.

Deploy the application

Before deploying the application make sure you have defined theGCLOUD_BUCKET environment variable in theapp.yaml file. Then, to deploy the application, run the following command:

npm run deploy -v<app-version># oryarn deploy -v<app-version>

This script will build the client + server code and deploy the application on Google Cloud. Butit will not promote the traffic to the specified version. This allows you tofirst test your application and make sure that everything run correctly.
Once you are ready to send the traffic to the new version, simply run:

npm run promote -v<app-version># oryarn promote -v<app-version>

Make changes to the client code

The purpose of this demo application is to showcase how to build a Node.js application in Node.js with gstore-node. The client (browser) javascript code has been reduced to the strict minimum for the purpose of the demo and "get the job done". All the source files for the client are in the/src/client folder.

Meta

Sébastien Loix –@sebloix

Distributed under the MIT license. SeeLICENSE for more information.

https://github.com/sebelga

About

Google Datastore Blog Application (demo)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp