├── README.md ├── index.js └── package.json /README.md: -------------------------------------------------------------------------------- 1 | # Creating Your Own NPX Introduction Command 2 | 3 | Creating your own `npx` introduction command can be a fun and useful project! The `npx` command allows you to run Node.js-based packages without having to globally install them. Here's a step-by-step guide to creating your own `npx` introduction command: 4 | 5 | ## Step 1: Choose a Package Name 6 | 7 | Decide on a unique name for your package. This name will be used to invoke your introduction command using `npx`. 8 | 9 | ## Step 2: Create a New Directory 10 | 11 | Create a new directory for your package. You can name it after the package name you chose in the previous step. 12 | 13 | ```bash 14 | mkdir my-npx-intro 15 | cd my-npx-intro 16 | ``` 17 | 18 | ## Step 3: Initialize Your Package 19 | 20 | Initialize your project as a Node.js package using the following command: 21 | 22 | ```bash 23 | npm init -y 24 | ``` 25 | 26 | ## Create an Executable Script 27 | 28 | Inside your project directory, create a JavaScript file that will serve as the executable script for your npx command. Let's call this file index.js. You can follow my example or edit it accordingly. 29 | 30 | ### Make sure to define bin in 'package.json' 31 | 32 | ```json 33 | "bin": { 34 | "my-npx-command": "./index.js" 35 | }, 36 | ``` 37 | 38 | ## Make the Script Executable 39 | 40 | In your terminal, make your script file executable by running: 41 | 42 | ### For Linux 43 | 44 | ```bash 45 | chmod +x index.js 46 | ``` 47 | 48 | ### For Windows 49 | 50 | **Note:** git should be installed. 51 | 52 | ```powershell 53 | git update-index --chmod=+x index.js 54 | ``` 55 | 56 | ## Test your command 57 | 58 | - Link the package using `npm link` 59 | - Test by running the command `npx package-name` 60 | - If it works as expected, make sure to unlink it using `npm unlink -g directory-name` 61 | 62 | ## Publish your package 63 | 64 | - Make an [npm account](https://www.npmjs.com/) 65 | - Login to your account using the command `npm login` 66 | - Publish the package using the command `npm publish` 67 | 68 | Send it to your friends and find a cool way to introduce yourself! 69 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // Function to log your details in the terminal 3 | function logDetails() { 4 | const message = "Hey there! I'm Haimantika, a Developer Advocate by profession. Currently hacking with frontend, building communities and public speaking!"; 5 | const twitterLink = "https://twitter.com/HaimantikaM"; 6 | const linkedinLink = "https://www.linkedin.com/in/haimantika-mitra/"; 7 | const wesbiteLink = "https://haimantika.com"; 8 | 9 | // Create a colorful box using ANSI escape codes 10 | const colorfulBox = ` \x1b[38;5;51m+---------------------------------------------------------------+ 11 | | \x1b[38;5;105m${message}\x1b[38;5;51m | 12 | +---------------------------------------------------------------+ 13 | | \x1b[38;5;93mTwitter:\x1b[0m \x1b[38;5;39m${twitterLink} \x1b[38;5;51m| 14 | | \x1b[38;5;93mLinkedIn:\x1b[0m \x1b[38;5;39m${linkedinLink} \x1b[38;5;51m| 15 | | \x1b[38;5;93mPortfolio:\x1b[0m \x1b[38;5;39m${wesbiteLink} \x1b[38;5;51m| 16 | +----------------------------------------------------------------+\x1b[0m`; 17 | 18 | // Log the colorful box in the terminal 19 | console.log(colorfulBox); 20 | } 21 | // Call the function to log your details 22 | logDetails(); 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hello-haimantika", 3 | "version": "1.1.1", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "bin": { 10 | "hello-haimantika": "index.js" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC" 15 | } 16 | --------------------------------------------------------------------------------