Skip to content

Simple tool to ensure google-cloud datastore targets an emulator, to avoid pollution of production data.

License

Notifications You must be signed in to change notification settings

beaulac/datastore-emulator-enforcer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

datastore-emulator-enforcer

Dead simple tool to make sure @google-cloud/datastore will target an emulator, so that tests/development won't pollute your production datastore.

To use it, simply require it before @google-cloud/datastore, e.g.

if (process.env.NODE_ENV !== 'production') {
  require('datastore-emulator-enforcer');
}

var myDatastore = require('@google-cloud/datastore')(/* init options */);

The enforcer throws an error if:

  • @google-cloud-datastore was required before the enforcer (i.e. datastore might already be pointing to production)
  • The emulator environment variables were not already present, and they could not be automatically determined & set.

If process.env does not already contain all emulator env vars, the enforcer will try to set them by running gcloud beta emulators datastore env-init. However, it won't override already-specified values.

  • Auto-determining emulator env vars only works if you're running a local emulator. You need to have installed the Google Cloud SDK
  • This functionality won't work if you're using the emulator on another host (, docker image, etc) – in that case, env vars must be specified ahead of time.

License

ISC

About

Simple tool to ensure google-cloud datastore targets an emulator, to avoid pollution of production data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published