“module.exports в JS” Ответ

Что такое синтаксис для экспорта функции из модуля в node.js

function foo() {}
function bar() {}

// To export above functions:
module.exports = foo;
module.exports = bar;

// And in the file you want to use these functions,
// import them like this:
const foo = require('./module/path');
const bar = require('./module/path');

QuietHumility

Как экспортировать класс в узле JS

class TestClass {
  
}

module.exports.TestClass = TestClass;
Embarrassed Earthworm

module.exports в JS

module.exports = {
    method: function() {},
    otherMethod: function() {},
};


const myModule = require('./myModule.js');
const method = myModule.method;
const otherMethod = myModule.otherMethod;
// OR:
const {method, otherMethod} = require('./myModule.js');
anas ben rais

Ответы похожие на “module.exports в JS”

Вопросы похожие на “module.exports в JS”

Больше похожих ответов на “module.exports в JS” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования