Create global variable instantiated when app loads


Hi guys, I am working on a project using Nativescript Core with Typescript and I want to use nativescript-couchbase plugin to store information. I would like to instantiate a variable so I can use in the whole application. I guess the file will be in app.ts, but I have tried to add it to global, but its not working…

Any suggestions? Thanks!


I would not suggest adding a variable to global name space until it’s really necessary, instead you can have your own TypeScript helper file that keeps references. For example,


export const variable = {};

From anywhere in app

import { variable } form "~/app-data";
// It's initialised when it's first required