Answer the question
In order to leave comments, you need to log in
Nodejs is there an auto-search for a module in the project tree?
Tell me, here I have a module that will return different settings for the application. Looks like this:
var params = function(){
var debugging = 0;
return {
debugging: debugging
};
};
module.exports = params;
var params = require('./app/params');
// or
var params = require('./params');
Answer the question
In order to leave comments, you need to log in
Autosearch is not needed, just imagine, what if he scans all folders with each call or what? At the start of the process, remember __dirname
or process.cwd()
and then count from it. In general, the config should be read 1 time at startup and there is nothing wrong if you write it to the global scope: GLOBAL.config = require('config.js');
and from anywhere in the program you will access it as: config.debugging
Or you can write it inside an object that you already have global, for example: application.config = require('config.js');
And then generally beautiful to write: application.config.debugging
In other words: USE THE GLOBAL LUKE
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question