How to add Global Variable That can be access to everywhere in the project #3966
Unanswered
naveensemidot
asked this question in
Help
Replies: 1 comment
-
Hey @naveensemidot! 👋🏻 There is nothing special to be done. AdonisJS is like any other Node.js application. // file: foo.ts
export const foo = 'acme' // file: bar.ts
import { foo } from './foo'
console.log(foo) // acme |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
Is there any way, I can add a Custom variable or a function to access anywhere in the project.
Refernce Code
For Custom Variable
Simillar to this
export const fileTypes = { CSS: "text/css", CSV: "text/csv", GIF: "image/gif", HTML: "text/html", };
Let Suppose in the validator.ts, I required to access fileTypes.CSV
For Member Function
export const replaceAllOccurance = (string, toReplace, withReplace) => { return string.split(toReplace).join(withReplace); };
And in the Controller or Model
I want to call replaceAllOccurance(param1,param2,param3);
How can we do in the AdonisJS 5.
Beta Was this translation helpful? Give feedback.
All reactions