How should modules be used efficiently from outside the node_modules folder?

I have a bunch of modules in my application, which is relative to me regarding the current script. The problem with this is, if I want to restructure my application, then I need to change tons of statements require.

So, I started using something like this:

//loader.js in root

"use strict";

exports.Logger = require('./core/logger');
exports.Module = require('./core/module');

And in my files I use requirelike this:

"use strict";

var Loader = require('../../loader');
var Logger = Loader.Logger;
var logger = new Logger();

So now, if I want to restructure common codes in my application, I have to change the request only in the file loader.js. This is a good decision? What are you using?

Is there a way to make it requirefully automatic if the name of the unique module is unique?

+4
source share
1

? :

/ app.js lib --/logger ----/index.js

app.js (./lib/logger)

-1

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


All Articles