“Węzeł funkcji eksportu JS” Kod odpowiedzi

Jaka jest składnia do eksportowania funkcji z modułu w 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

eksport modułu w węźle JS

var users = [
    { userName: "BarneyRubble", age: 38   },
    { userName: "WilmaFlintstone", age: 37 },
    { userName: "FredFlintstone", age: 36 }
];

module.exports.getAllUsers = function(){
    return users;
}
Magnificent Millipede

Jak wyeksportować funkcję w NodeJS

function foo(x, y) {
  return x + y;
}

function bar(x, y) {
  return x - y;
}

//You can also export numbers, classes, objects, etc
const foobar = 33;

module.exports = { foo, bar, num };
EnZon3

Węzeł funkcji eksportu JS

module.exports.yourFunctionName = function()
{

}
Magnificent Millipede

Odpowiedzi podobne do “Węzeł funkcji eksportu JS”

Pytania podobne do “Węzeł funkcji eksportu JS”

Więcej pokrewnych odpowiedzi na “Węzeł funkcji eksportu JS” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu