- Notifications
You must be signed in to change notification settings - Fork6
Google Datastore Blog Application (demo)
License
sebelga/google-datastore-blog-app
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
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.
I wrotea multi-part tutorial on Medium that goes through the code in this repository. You canfint it here
- 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
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 😄.
Before starting make sure that you have the necesary dependencies installed on your system.
- node (8 +) & npm
- Google SDK (you candownload it here) with the
gcloud
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.
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:
Enable billing for the project (Enable billing)
Enable the Google Cloud Datastore API (Enable the API)
Set the project asdefault in gcloud
gcloud configset project<your-project-id>
Once you have your project configured in Google Cloud, install the application dependencies with
npm install# oryarn
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
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
npmstart-local
You can now navigate tohttp://localhost:3000
and start creating posts and comments.
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>
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.
Sébastien Loix –@sebloix
Distributed under the MIT license. SeeLICENSE
for more information.
About
Google Datastore Blog Application (demo)
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.