global
Introduction
The global function is a way to share global values such as a logger, metrics, or even middleware and access them in all of your files without having to manually import them.
This feature does not work in serverless mode!
Usage
Simply create a light.config.js
file in the ROOT of your project (i.e. on the same level as the routes folder)
If you are using light dev
or light server
, the global variables get injected into the server under the light
variable. This is controversial because many people are against global variables and they are right, BUT if you do atomic actions such as logging or incrementing a counter, it shouldn't really matter.
If you are using a serverless environment, you will have to manually call the global function. In any of your routes, just invoke the global function.
Last updated