0

I have 2 routes (example1 and example2), I want to have a global general variable that can be accessible by these 2 routes.

One example:

//api/variable.ts
let test = 0
//api/example1.ts

setTest =() => {
  test=2
}
//api/example2.ts

getTest =() => {
  return test
}

Now I want to call some routes and the value of the variable should be updated

// mainFile.ts

setTest()
getTest() // It should return 2, but it returns 0

How could I create a global variable like that? I tried to use a singleton class just for this variable, but it didn't work.

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.