C
C
Cube2019-10-23 12:59:29
JavaScript
Cube, 2019-10-23 12:59:29

How to set a global variable in sails.js like in lodash?

In sails.js, you can call lodash this way _.sort()anywhere in the project. For example, there is a key
in globals.js_: require('lodash') .
If you add there moment: require('moment'), it will not work.
How to set a similar way of calling, only for moment.js?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2019-10-23
@sergiks

lodashThey write about it in the Sails documentation:

Async ( async) and Lodash ( _)
Sails also exposes an instance of lodash as _, and an instance of async as async. These commonly-used utilities are provided by default so that you don't have to npm install them in every new project. Like any of the other globals in sails, they can be disabled.

The file globals.jsis only meant to disable some default globals:
// config/globals.js
module.exports.globals = {
  _: false,
  async: false,
  models: false,
  services: false
};

And your line is perceived, apparently, in the same way as - i.e. just doesn't disable that global variable. So, probably, the working option is to include moment in each module where it is required. _: require('lodash')_: true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question