L
L
learn0012016-04-25 10:55:40
Node.js
learn001, 2016-04-25 10:55:40

What does this mean when connecting the module?

I encountered such a connection of the module.
e9e0e93421c549e4b212a9db4d7a2e25.png3300de06c7de4c8abfc1726026a12c90.png
Kantor showed so
4c6728b7654f43c286c76bb76aed7109.png
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

3 answer(s)
T
Timur Shemsedinov, 2016-04-25
@MarcusAurelius

var config = require('config'); // подгрузка npm модуля с именем config
var config = require('./config'); // подгрузка файла config.js из текущего каталога
var config = require('../config'); // подгрузка файла config.js из каталога на 1 выше
var config = require('../config.js');  // то же, что и предыдущая строка

A
Artyom Egorov, 2016-04-25
@egoroof

// config.js
var config = {
    host: 'localhost'
    // и т.д.
};
module.exports = config;

// другой файл
var config = require('../config');
console.log(config.host); // localhost

S
Super User, 2016-04-26
@sergeystepanov1988

Firstly, exports is not recommended , it is better:
Secondly, it is enough to write:

var config = {...};
module.exports = config;

Then you don't have to write this crap:
var config = require('../config').config;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question