I need to write function that will be used in several places, for example, middlewares or modules. How and when can I put this function and use it? Thanks.
Asked
Active
Viewed 37 times
-1
-
I'm using a strongloop framework. – Igor Shainsky Mar 08 '16 at 13:56
2 Answers
0
you can write function in model.js or js files and put in common directory, so you can access several places, refer this link. https://docs.strongloop.com/display/public/LB/common+directory

Riaz
- 561
- 6
- 15
0
One way of doing it could be to add it to your server as a function by require'ing it in the server.js,
eg.
var app = module.exports = loopback();
app.logger = require('../common/utils/logging');
The required file would then have to export the functionality thorugh module.exports
From a server context file you could then call app.logger or from a model.js you can call it though model.app.logger.

Mikael Jensen
- 140
- 8