Hackviking He killed Chuck Norris, he ruled dancing so he took up a new hobby…

3Feb/200

Google Cloud Functions local testing – auto releod

Cloud Functions is Google Cloud’s event-driven serverless compute platform. Run your code locally or in the cloud without having to provision servers. Go from code to deploy with continuous delivery and monitoring tools. Cloud Functions scales up or down, so you pay only for compute resources you use. Easily create end-to-end complex development scenarios by connecting with existing Google Cloud or third-party services.

It's easy enough to get up and running with a local dev environment but with the basic setup you need to restart the dev server on every file change. Doing a lot of Google AppEngine development recently I got use to the dev server reloading changed files. When you have the basic environment up and running (specified here: https://cloud.google.com/functions/docs/functions-framework) just follow these simple steps.

npm -g install npm-watch

Then open the basic package.json file and add the highlights below:

{
  "name": "reloadTest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "Kristofer Källsbo",
  "license": "ISC",
  "dependencies": {
    "@google-cloud/functions-framework": "^1.4.0"
  },
  "watch": {
    "start": "*.js"
  },
  "scripts": {
    "watch": "npm-watch start",
    "start": "functions-framework --target=reloadTest"
  }
}

Now run your dev environment with

npm run watch

And whenever you update a file in your project npm will reload the dev environment.

Posted by Kristofer Källsbo

Comments (0) Trackbacks (0)

No comments yet.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

No trackbacks yet.