J
J
Jeff_Parker2022-02-08 13:34:13
JavaScript
Jeff_Parker, 2022-02-08 13:34:13

How to pass a parameter to an exported function?

It is necessary to pass an array to the setValues() function, I write on node.js
The function itself is in the index.js file

module.exports = async function setValues(arr){
//some code
console.log(arr)
}

The function that calls it in the test.js file
const exported = require('./index')
async function fun(){
let array = []
array .push(1)
//some code
exported.setValues(array)
}

I get an error in the log - TypeError: exported.setValuesis not a function

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Konstantinov, 2022-02-08
@Jeff_Parker

exported is already an import function because in index.js the exported object is the function
https://www.tutorialsteacher.com/nodejs/nodejs-mod...

const exported = require('./index');

async function fun() {
  exported([1]);
}

PS:6202523a80667626136490.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question