While attempting to utilize Google Cloud Functions for API calls, I encountered an error upon deployment. The site displayed the following message:
Function failed on loading user code. Error message: Code in file app.js can't be loaded. Is there a syntax error in your code? Detailed stack trace: ReferenceError: app is not defined
What could possibly be causing this issue?
The files involved are as follows:
//app.js
exports.simple = app;
The purpose of App.js is to invoke the Google Cloud Function that executes the function call "simple". IMAGE : 1
// server.js
// BASE SETUP
var express = require('express');
var app = express();
const port = 8080;
// ROUTES
var router = express.Router(); // get an instance of router
router.use(function(req, res, next) { // route middleware that will happen on every request
console.log(req.method, req.url); // log each request to the console
next(); // continue doing what we were doing and go to the route
});
app.use('/',require ('./Routers/API/home'));
app.use('/leads',require ('./Routers/API/leads'));
app.use('/people',require ('./Routers/API/people'));
app.use('/companies',require ('./Routers/API/companies'));
app.use('/opportunities',require ('./Routers/API/opportunities'));
app.use('/projects',require ('./Routers/API/projects'));
app.use('/tasks',require ('./Routers/API/tasks'));
app.use('/activities',require ('./Routers/API/activities'));
app.use('/', router); // apply the routes to our application
// START THE SERVER
// ==============================================
app.listen(port);
console.log('Listening ' + port);
module.exports = {app};