Node.js requires () code completion in WebStorm

In Node.js and WebStorm, we want to avoid using require()relative file paths, for example. require('../../../../../ugly/path/to/file')

We tried to use the include function from here: https://coderwall.com/p/th6ssq/absolute-paths-require

global.base_dir = __dirname;
global.abs_path = function(path) {
  return base_dir + path;
}
global.include = function(file) {
  return require(abs_path('/' + file));
}

global.include basically requires (), but uses an absolute path, eliminating the need for all ../../../.

The problem is that the WebStorm method hinting and autocomplete does not work with this. So, is there any workaround to complete the WebStorm method and require () absolute paths?

+4
source share

Source: https://habr.com/ru/post/1655692/


All Articles