Articles by Victoria

Automate GitHub: Build a CLI App with Node.js #1

Apr 21, 20211 min read
cover

At the end of this 2-part tutorial, you will have a simple CLI tool that can automate the process of pushing a local git repository to your GitHub.

Prerequisites

• Beginner experience with Node.js
• Node and npm installed
• Git installed
• Code Editor installed

Step 1: Set up a Node.js project

Initialize your project:

mkdir cli-app
cd cli-app
npm init

Install dependencies:

npm install figlet chalk clear @octokit/rest commander inquirer configstore simple-git glob

Step 2: Create files

Create these files in the root directory:
1. index.js
2. creds.js
3. new_repo.js

Step 3: Index.js

Import dependencies and create the init command with commander.

Step 4: Generate a Token

Go to GitHub Settings → Developer Settings → Personal Access Token → Generate new token.

Step 5: Creds.js

Create authentication function using octokit and inquirer.

Step 6: Configstore

Use configstore to persist and reuse the GitHub token.

Conclusion

In Part 1, we created authentication for our CLI tool. In Part 2, we'll complete the app by implementing repo creation and file pushing. Thanks for reading!

Share:

More Articles