app.js:

var script = require('./script'); script.testJs(); 

script.js:

 function testJs() { //... }; 

app.js and script.js are in the same folder. By doing

 script.testJs(); 

TypeError , Message: script.testJs error is not a function . What's wrong? Add. Information: using Visual Studio Code, jsconfig.json:

 { "compilerOptions": { "target": "ES6" }, "exclude": [ "node_modules" ], "files": [ "~/" ] } 

    1 answer 1

    script.js

     function testJs() { ... } module.exports = { testJs: testJs }; 

    app.js

     var script = require('./script'); script.testJs(); 

    using require you do not import something into the local scope, but get the contents of the module.exports object filled in the module specified in require