Reputation: 473
I'm working on a Node.js file to automatically create a new Github repo.
When I run curl -u 'BretCameron' https://api.github.com/user/repos -d '{"name":"test_repo"}'
in the terminal, it asks me for my GitHub password and then creates the new repo.
But I can't get this to work in Node, even though the git
commands in my sample code are working fine:
const { exec, execSync } = require('child_process');
function run(func) {
console.log(execSync(func).toString())
}
run('touch README.md');
run('git init');
run('git add README.md');
run('git commit -m "First commit"');
exec(`curl -u 'BretCameron' https://api.github.com/user/repos -d '{"name":"test_repo"}'`));
I have tried with the exec
and execSync
functions from the child_process
module, as well as putting it into my helper function run
. Can anyone offer some advice?
Upvotes: 0
Views: 254