Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  148] [ 4]  / answers: 1 / hits: 6228  / 4 Years ago, mon, june 22, 2020, 12:00:00

How do I call a function which is stored in an other function?


I created two js files (File A and File B). In file A I created a function called "getFiles" and I would like to call this function in File B.


File A:


export function getFiles(input){
...
}

File B:


import {getFiles} = from './A.js';

getFiles('');

But I'm getting the error message "Module '"./A.js"' has no exported member 'getFiles'."


Does anyone know how I can call the function in File B?


More From » function

 Answers
9

In the js File A I had to create a class to be able to export the function.
The class had to be exported with "module.exports"


module.exports = class A {
getFiles(input) {
...
}
}

And now in File B I had to add a require line to this class:


const A = require('./A.js');

And now I can call my function "getFiles" from File A:


// vscode extension function
function activate(context) {
const a = new A();
a.getFiles('');
}

https://nodejs.org/api/modules.html#modules_modules


[#3414] Thursday, June 18, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianom

Total Points: 601
Total Questions: 98
Total Answers: 109

Location: Kenya
Member since Fri, Dec 23, 2022
1 Year ago
lucianom questions
Tue, Feb 22, 22, 00:00, 2 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Sun, Jan 24, 21, 00:00, 3 Years ago
Sat, Aug 15, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
;