Google Cloud Functions, Node JS 8.9.x (LTS) and KOA library
Asked Answered
H

4

5

How can I use Koa library, the express replacement, in Cloud Functions?

I know KOA use all great ES2017 and make more use of Async use of JavaScript.

or it might not be needed at all working with Cloud Functions because the Firebase system won't send multiple calls to the same Cloud Function until it ends the previous one?

it unclear to me.

it know demands Node 8.x and I know the NodeJs 8.9.x, has now LTS.

Hauler answered 8/12, 2017 at 10:8 Comment(1)
Had the same problem. Warning: You're using Node.js v8.11.1 but Google Cloud Functions only supports v6.11.5.Petal
G
4

Reading from cloud functions doc:

Base Image Cloud Functions uses a Debian-based execution environment and includes contents of the gcr.io/google-appengine/nodejs Docker image, with the Node.js runtime installed in the version, specified above:

FROM gcr.io/google-appengine/nodejs
RUN install_node v6.14.0

To see what is included in the image, you can check its GitHub project, or pull and inspect the image itself. Updates to the language runtime (Node.js) are generally done automatically (unless otherwise notified), and include any changes in the definition of the base image.

And I saw a pull request back in November 2017, adding Nodejs v8. Here's hoping it can finally land in Google Cloud Functions 🤞🏻

UPDATE: Google Cloud Functions now support Node.js 8 and even Python!

Groh answered 30/5, 2018 at 22:43 Comment(2)
AWS is already on v8, GCP should also offer it, the longer they wait, they more they will lose to AWS...Hylomorphism
not just AWS, Azure Functions is 8.9.4 at a time of writing. Hoping Google can pick up the slack.Groh
H
3

Referring to the release notes from Google... Cloud Functions Release Notes

Node version supported is still at v6, same for firebase. You need to wait awhile before they release it in v8. Am pretty sure they will move to v8 when v6 no longer supported, but hopefully earlier...

Hylomorphism answered 16/1, 2018 at 19:32 Comment(0)
D
0
Use babel:

index.js:
----------=

'use strict';

require('@babel/register')
require('babel-polyfill')
const http = require('http')

const createApp = require('./app/app.js')
const handle = createApp().callback()

if (process.env.IS_LOCAL_DEPLOYMENT) {
    // to use same code in local server
    http.createServer(handle).listen(3000)
} else {
    module.exports.http = (request, response) => {
        handle(request, response)
    };
}

app.js:
--------

'use strict';

const Koa = require('koa')

module.exports = () => {
    const app = new Koa()

    app.use(......)

    return app
}

package.json
------------

  "scripts": {
       .
       .
    "start": "export IS_LOCAL_DEPLOYMENT=true && node index"
       .
       .
  }
Dom answered 17/7, 2018 at 20:1 Comment(0)
P
0

I just saw in Cloud Functions Console editor for one of my functions that Node 8 is now a runtime option. See screenshot:

enter image description here

Prospero answered 19/7, 2018 at 23:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.