luyue
v1.0.1
Published
Personal CLI business card for Luyue Zhang
Downloads
101
Maintainers
Readme
Create NPX Business Card
Open a terminal and type npx luyue to see my business card.
I learned the idea from the article Write a Simple npx Business Card, then made some changes on top of it.
I will share how I accomplished this in detailed instructions below, I hope it will help you build your own CLI project. If you would like to leave a star, thank you!
Feel free to experiment, style it your way, and share it with others. Enjoy!
Before You Start
Your computer must have Node.js installed.
Check it with:
node -v
npm -v If both show version numbers, you are ready!
Tutorial
Create a New Project Folder
Make an empty folder anywhere you like. Inside this folder, run:
npm init -y This creates a basic Node project automatically. It generates a package.json file, which keeps project info and settings.
You may find this from your package.json:
"bin": {
"luyue": "cli.js"
}This tells npm which command to run and which file to execute. If you want your own custom command (e.g. npx your_name), you need to write:
"bin": {
"your_name": "cli.js"
}Please keep in mind that your_name must be a valid npm command name and must not conflict with existing global commands.
Install Dependencies
We need two packages:
npm install [email protected]
npm install chalk@4 These versions work with CommonJS and let us use require() without errors.
Create files
- Create the file:
lib/data.js. This file will store your personal information. You can follow the structure of my data file or create your own. - Create
index.js. This file reads your info and returns your final card string. You can follow myindex.jsor read the official docs for boxen and chalk if you want to customize the style. - Create
cli.js. This file will run when someone typesnpx your_name.
At the top ofcli.js, add:#!/usr/bin/env node. This tells the system to run the file with Node.
Then add:const { buildCard } = require('./index') // loads your function from index.js console.log(buildCard()) // prints the card - On macOS or Linux, you also need to run:
chmod +x cli.js. This makes the file executable (Windows users do not need this).
Test Locally
- Run:
node cli.js. You should see your card in the terminal. - Optional: When you run
npm link, npm registers your package as a global command on your system.
But, this is only for local testing and is not required for publishing.npm link luyue
Publish to NPM
First, go to npmjs.com and create an account. Then log in from the terminal: npm login.
Now publish your package (first time only): npm publish --access public.
Before publishing your package, you may want to check whether the package name is already taken:
npm view package-nameIf the package does not exist, npm will return a 404 error message.
If you want to update your package later after publishing, don't forget to increase the version number in package.json (for example 1.0.0 to 1.0.1), then run npm publish to update your changes.
After you published your package, you may want to check the published version list:
npm view your_package_name versions