"Error: Unable to find 'App' in Google Cloud Function code utilizing Express framework

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};

Answer №1

As noted in a previous post, incorporating express into a Google Cloud Function involves placing your server code within the main file and defining the app variable as the entry point.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I find myself trapped in the depths of callback hell. Can anyone offer guidance on the most effective approach to tackle this

I'm currently working on developing a trucking app similar to Uber. The main challenge I'm facing is dealing with callback hell while trying to match trucks with posted loads efficiently and ensuring good performance simultaneously. I'm usin ...

JavaScript finding items in an array

The main issue I am encountering involves receiving a notification when the term (city name within the project) entered by the user in JqueryUI Autocomplete does not match anything in the collection (e.g. user entered "My Sweet City" and it does not matc ...

Developing a single page that caters to various users' needs

Greetings to all my friends, As a front end developer, I am in the process of implementing a dashboard for a project that involves different users with varying permissions. Each user should only have access to certain parts of the page, resulting in some ...

Updating parameters in Node.js with mongoose

script.js var mongoose = require('mongoose'); var Schema = mongoose.Schema; var scriptSchema = new Schema({ status: {type: String, default: 'INCOMPLETE'}, code: String, createdDate: {type: Date, default: Date.now}, user: {t ...

Having trouble accessing a PDF file using gview

Having trouble opening a document I am unable to preview the documents and I'm not sure what I'm missing. I have read through various StackOverflow questions and answers related to this issue, but still no luck. url = http://192.168.0.6:8077/ ...

Creating interactive text using Three.js and dat.gui

Exploring the possibilities of dynamic rendering user inputted text with three.js and dat.gui, I have developed a code snippet to display the text: var displayGui = function(){ var gui = new dat.GUI(); var parameters = { message:"sample", spin ...

Function that activates traffic lights

Currently, I'm encountering errors while working on this project in Notepad. Can you help me figure out what's wrong with my code? I'm attempting to create an onload traffic light using an object array. The requirement is to implement this f ...

Combining multiple objects in an array to create a single object with the aggregated sum value can be achieved using JavaScript

I am working with an array that contains numbers of array objects, and I need to merge these arrays into a single array with unique values for content and the sum of values for total as shown in the desired result below. Any assistance would be greatly app ...

JavaScript - Capture user input and store it in a cookie when the input field is changed

Any help with my issue would be greatly appreciated. I'm currently working on saving the value of a form input type="text" to a cookie when the input has changed. It seems like I'm close to getting it right, but unfortunately, it's not worki ...

Encountering a display issue within a port using Express

Recently, I enrolled in an advanced ExpressJS course. While exploring the course website, I stumbled upon the "hello world" section. Intrigued, I decided to copy and paste the code provided below: const express = require('express') const app = ex ...

Troubleshooting why passing $var within @{{ }} in Vue.js + Laravel is not functioning as expected

I am integrating Algolia Vue-InstantSearch into a Laravel Project. Since we are working with a blade file, the {{ }} symbols will be recognized by the php template engine. To ensure that they are only understood by Vue in JavaScript, we can add an @ prefix ...

Halt spread: descend in a bubble?

It seems that the issue at hand may not be related to propagation, but rather a design flaw. I have come across information suggesting that propagation problems tend to bubble up, however, let me explain my situation. I am working with a table edit grid. ...

Are async.series and event driven code synonymous?

When using node js for my application, I have code examples like the following: userProvider.uploadImage(formData.imageSmall, 'full', function(err) { if (err) throw err; userProvider.uploadImage(formData.image, 'small&apos ...

Remove the identity from the array within the nested structure

I am currently facing a challenge where I can only delete the first id (in this case, the id with "12345"). My goal is to remove the row with id 2 from within the books array. Library Table: { "_id": { "$oid": "12345" }, "librar ...

Activate the function only once the display has finished rendering all items from ng-repeat, not just when ng-repeat reaches its last index

Currently, I am generating a list using ng-repeat and each iteration is rendering a component tag with a unique id based on the $index value. The implementation looks like this: <div ng-if="$ctrl.myArr.length > 0" ng-repeat="obj in $ctrl.myArr"> ...

Troubleshooting issues with adding child elements in JavaScript

Styling with CSS: ul #allposts li{ height: 50px; width: 50px; background-color: yellow; border: 1px solid yellow; } Creating HTML structure: <ul id = "allposts"></ul> Adding JavaScript functionality: var container = documen ...

Transform an Angular 2 application to seamlessly incorporate an SDK

I have been working on an Angular 2 application and I am curious if it is feasible to transform this into an SDK that can be easily integrated into other applications by simply adding script tags in their headers. If this conversion is not achievable, co ...

Angular-cli working in conjunction with an express project

I am currently working on a project that involves Express, MongoDB, and the REST API. I now want to integrate Angular into the project using angular-cli. However, I have several questions about the process. Here is the current structure of my project: htt ...

Working with Javascript objects and arrays

Need assistance with manipulating/updating a JavaScript array. Hoping for some help. The initial array looks like this: array('saved_designs'=array()); In Javascript JSON format: {"saved_design":{}} I plan on adding a label and its associa ...

Error: The property 'ss' cannot be accessed because it is undefined

Our main source page will be index.html, while Employees.html is where our results end up. An error occurred: TypeError - Cannot read property 'ss' of undefined Error in the code: let rating = req.body.ss; Seeking assistance please >< C ...