Reputation: 192
I have the following class:
const exec = require('child_process').execSync;
class Git {
static branchExists (branchNameToCheck) {
return ( exec(`git rev-parse --verify --quiet ${branchNameToCheck} > /dev/null`).length > 0 );
}
}
module.export = Git;
This is called in the following (simplified) script:
#!/usr/bin/env node
const Git = require('./classes/Git');
if (Git.branchExists('develop')) console.log('success');
I get the following error:
Git.branchExists();
^
TypeError: Git.branchExists is not a function
Why is it not recognising branchExists
as a function? When I run console.log(Git)
I get {}
.
Upvotes: 0
Views: 33
Reputation: 801
I think it may just be a typo: module.export = Git;
-> module.exports = Git;
. If you don't define module.exports, the imported object ("Git" in this case) will be an empty object https://stackabuse.com/how-to-use-module-exports-in-node-js/
Upvotes: 2