Answer the question
In order to leave comments, you need to log in
What does this mean when connecting the module?
I encountered such a connection of the module.
Kantor showed so
If, after the connection, remove .config, it stops working. Proyanite why put an end and write the name? Version difference?
Answer the question
In order to leave comments, you need to log in
var config = require('config'); // подгрузка npm модуля с именем config
var config = require('./config'); // подгрузка файла config.js из текущего каталога
var config = require('../config'); // подгрузка файла config.js из каталога на 1 выше
var config = require('../config.js'); // то же, что и предыдущая строка
// config.js
var config = {
host: 'localhost'
// и т.д.
};
module.exports = config;
// другой файл
var config = require('../config');
console.log(config.host); // localhost
Firstly, exports is not recommended , it is better:
Secondly, it is enough to write:
var config = {...};
module.exports = config;
var config = require('../config').config;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question