Nbb on Google Cloud Functions

June 6, 2023 ยท View on GitHub

This article is based on this gist by Jack Rusher. Thanks Jack!

Creating an nbb google cloud function

All you need to do to get nbb running on GCP Cloud Functions is the following:

package.json:

{
    "type": "module",
    "scripts": {
        "start": "functions-framework --target=hello"
    },
    "main": "index.mjs",
    "dependencies": {
        "nbb": "~1.2.174",
        "@google-cloud/functions-framework": "~3.2.0"
    }
}

index.mjs:

import { loadFile } from 'nbb';

const { hello } = await loadFile('./hello.cljs');

export { hello }

hello.cljs:

(ns hello)

(defn hello [req res]
  (js/console.log req)
  (.send res "hello world"))

;; export
#js {:hello hello}

Then deploy the function with:

$ gcloud functions deploy hello --runtime nodejs20 --trigger-http

Also see Nbb on AWS Lambda.