Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

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

Posted on

     

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 commandnpm login. Now you're ready, navigate to your project folder and run thenpm publish command.

Package.json

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

  1. The value of "version" should be updated every time you run thenpm 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 thebin key.
  3. If you want the GitHub repository link to appear on the npm page, add therepository 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 thatnpx 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 thelink 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!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Hi, I'm Giuliano and I'm a full stack web developer based in Rome. I love playing around with code trying out new things. I love to share knowledge and get into inspiring conversations.
  • Location
    Rome, Italy
  • Pronouns
    he/him
  • Work
    Full-stack web developer and dev mentor
  • Joined

More fromGiuliano1993

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp