1

Is there any problems when it comes to using global variables in a code that runs on Google App Engine ?

Let's say that we have :

const ws = [];
function newUser(){
    ws.push({name:"user"});
}

I know that if we run this code locally, the array will hold the data that has been added to it as long as the program is running and not terminated, is this the case when we run this code on Google App Engine, is the serverless architicture going to affect this somehow?

maysara
  • 113
  • 4

1 Answers1

1

The behavior of a Global Variable in App Engine is similar to your local setup. In this case, the array will hold the data until the program ends or the machine dies.

What you have to take into consideration is that having multiple instances means that you may have different values for the same variable in each instance. You can preserve global variables for multiple instances using an external data source like Datastore.

Let me know if you have more doubts about this.

Chris32
  • 130
  • 8