Skip to content

Instantly share code, notes, and snippets.

Grant Timmerman grant

Block or report user

Report or block grant

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View index.html
<!DOCTYPE html>
<html lang="en">
<title>Hello, GAPI</title>
Hello, GAPI!
<script src=""></script>
View index.html
<script src=""></script>
grant / index.js
Last active Aug 27, 2019
Express Routing: Router
View index.js
const express = require('express');
// Create an Express object and routes (in order)
const app = express();
app.use('/users/:id', getUser);
app.use('/users/', getAllUsers);
// Set our GCF handler to our Express app.
exports.users = app;
grant / index.js
Last active Aug 27, 2019
Express Routing: Switch (2)
View index.js
export function getAllUsers(req, res) {
// TODO: Get users from a database
res.send(['Alice', 'Bob']);
export function getUser(req, res) {
// TODO: Get user details
res.send({ name: 'Alice', location: 'LAX', });
grant / index.js
Last active Aug 27, 2019
Express Routing: Switch
View index.js
exports.users = (req, res) => {
// Get the first part of the URL
switch (req.url.split('/')[1]) {
case '': getAllUsers(req, res); break;
case 'user': getUser(req, res); break;
default: getDefault(req, res);
grant / index.js
Last active Aug 3, 2019
Run Node 12 index.js
View index.js
const Greeter = require('./greeter');
exports.function = (req, res) => {
const g = new Greeter();
// Can't access private fields
// greet.#name = 'NewName';
grant / greeter.js
Created Aug 3, 2019
Run Node 12 greeter
View greeter.js
class Greeter {
#name = 'Functions Framework';
get name() {
return this.#name;
set name(name) {
this.#name = name;
sayHello() {
return `Hello, ${this.#name}`;
grant / package.json
Created Aug 3, 2019
Run Node 12 package.json
View package.json
"name": "ffnode12",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "functions-framework"
"dependencies": {
"@google-cloud/functions-framework": "^1.2.1"
grant / Dockerfile
Created Aug 3, 2019
Run Node 12 Dockerfile
View Dockerfile
# Use the official Node.js 12 image.
FROM node:12
# Create and change to the app directory.
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
# Install production dependencies.
grant / index.js
Last active Jul 20, 2019
GCF Debugging VSC List Google APIs
View index.js
const {google} = require('googleapis');
* Returns a list of Google APIs and their descriptions.
* @param {Express.Request} req The API request.
* @param {Express.Response} res The API response.
exports.listGoogleAPIs = async (req, res) => {
// Call the API
const apis = await google.discovery('v1').apis.list();
// Build the response
You can’t perform that action at this time.