-1

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.

2 Answers2

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.