DEV Community

Cover image for Let's create an NPX command
Giuliano1993
Giuliano1993

Posted on

2

Let's create an NPX command

Good morning everyone and happy MonDEV! ☕

This week I'm here with a question, or rather a proposal, if you've never done it: have you ever created an executable command with npx?
Last week, I was developing some front-end components for Vue.js, and, partly out of laziness and partly out of habit from using Laravel's Artisan command-line tool, which allows generating a boilerplate for almost anything, I wondered if there was something similar for Vue.js. Not finding anything like that, I thought of taking the opportunity to try something new, namely creating an npx command to automate this (albeit brief) process. After struggling a bit, I managed to come up with a command that did exactly what I needed; needless to say, regardless how simple the task was, the satisfaction was great! Have you ever tried it? As a suggestion for the week, I propose you give it a try, with code of your choice. Below are just a few tips:

How to publish on npm

If you haven't already, create an account on npm, so you can publish your packages. After that, in your terminal, you'll need to run the command npm login. Now you're ready, navigate to your project folder and run the npm publish command.

Package.json

In your package.json, you'll need to consider a couple of things:

  1. The value of "version" should be updated every time you run the npm publish command; otherwise, you'll get a version incompatibility error.
  2. In the simplest case, you'll have only one entry point for your command: pass the path to the file to be executed as the value for the bin key.
  3. If you want the GitHub repository link to appear on the npm page, add the repository key and give the repository URL as the value.
Working with FileSystem

If, like me, you choose a project that works with the filesystem, remember that npx downloads the package to a temporary folder on your PC (different depending on your operating system), not in the folder from which the command is launched; keep this in mind when working with paths!


If you want to take a look or try using the command I developed, here's the link to the repo with the documentation; of course, any feedback is welcome 😊. If you take on the challenge and develop even a small command, write to me; I'm curious to see the ideas that come out. I'll be waiting for you in the comments on dev.to 😃 . As always, I hope these tips can be useful to you and have given you a good starting point for a small personal project to take on this week!
I just have to wish you a good day, Happy Coding 1_0!

Image of Wix Studio

2025: Your year to build apps that sell

Dive into hands-on resources and actionable strategies designed to help you build and sell apps on the Wix App Market.

Get started

Top comments (0)

Cloudinary image

Zoom pan, gen fill, restore, overlay, upscale, crop, resize...

Chain advanced transformations through a set of image and video APIs while optimizing assets by 90%.

Explore

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay