Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Main Application File
// imports
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
// setup
// POST endpoint"/", (req, res) => {
// parse body
if (!req.body) {
const msg = "no Pub/Sub message received";
console.error(`error: ${msg}`);
res.status(400).send(`Bad Request: ${msg}`);
if (!req.body.message) {
const msg = "invalid Pub/Sub message format";
console.error(`error: ${msg}`);
res.status(400).send(`Bad Request: ${msg}`);
// parse message
const pubSubMessage = req.body.message;
const originatorMessage = Buffer.from(, "base64").toString().trim();
const now = new Date();
// log output
console.log(`${originatorMessage} says the time is ${now.toString()}`);
// start server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => console.log(`listening on port ${PORT}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.