Introduce yourself with an npm package

Cover Image for Introduce yourself with an npm package

Go to your terminal and type: npx hello-haimantika

Watch it in action here 👇

Looks interesting right? Building it is easy too. Whether you're a seasoned developer or just starting out, this guide will help you craft a unique way to make your introduction stand out.

But, first.

What is an npm package?

An npm package is a reusable piece of software, a module or library, that can be downloaded from the npm registry using the Node Package Manager (npm). It can include anything from a small utility function to a complete application framework, facilitating code sharing and reuse within the JavaScript ecosystem. Packages are typically installed as dependencies in Node.js projects to extend functionality or add new features.

Getting Started

Step 1: Choose a package name

Step 2: Setup your project directory

mkdir my-npx-intro
cd my-npx-intro

Step 3: Initialize your package

npm init -y

Creating an executable script

Your NPX command will run a JavaScript file, which acts as the entry point. Inside your project directory, create a file named index.js. This file will contain the code executed when your NPX command is invoked. Feel free to customize the content of this file to best introduce yourself.

For your script to be executable through NPX, you must declare it in your package.json file. Add the following lines:

"bin": {
  "my-npx-command": "./index.js"
}

Replace "my-npx-command" with whatever you want your command to be called.

Making the script executable:

Before testing, ensure your script file is executable. On Linux, use the command:

chmod +x index.js

Windows users will need Git installed to run:

git update-index --chmod=+x index.js

Testing your command:

Before publishing, test your command locally by linking your package with npm:

npm link

Now, you can test it by running npx <package-name>. If everything goes as planned, don't forget to unlink your package:

npm unlink -g <directory-name>

Publishing your package

To share your command with the world, you'll first need an npm account. After creating one, log in via the terminal:

npm login

Finally, publish your package with:

npm publish

Share your introduction

Congratulations! You've just created and published your own NPX introduction command. It's time to share it with your friends, colleagues, or at meetups (if you are presenting).

You can find the code here.