Skip to content

Instantly share code, notes, and snippets.

@devinschumacher
Last active June 13, 2024 01:40
Show Gist options
  • Save devinschumacher/30cda55546a9311df789184a727c3f8d to your computer and use it in GitHub Desktop.
Save devinschumacher/30cda55546a9311df789184a727c3f8d to your computer and use it in GitHub Desktop.
dlx: What is the "dlx" in `pnpm dlx` do?
tags
glossary, pnpm

What is dlx?

dlx stands for "Download and Execute".

dlx is a feature provided by pnpm (a fast and disk space efficient package manager for Node.js) that allows you to download and execute a package directly, without installing it globally or adding it to your project's dependencies.

The dlx command is useful when you want to use a package temporarily without installing it permanently in your project or globally on your system. It ensures that you are always using the latest version of the package and helps keep your project's dependencies clean.

Cons

  • Package compatibility: When using pnpm dlx, you are always using the latest version of the package. While this can be beneficial, it also means that if there are breaking changes or incompatibilities between the latest version and your project's dependencies, it may cause issues.
  • Disk space: A primary benefit of pnpm is that it's designed to be disk space efficient, using dlx frequently for different packages can still consume some disk space as it downloads the packages each time.

Example usage & no dlx equivalent

pnpm dlx nuxi@latest init <project-name> # creates a new nuxt project

If you don't want to use dlx, then you would need nuxi installed on your system globally, or not.

Global install:

pnpm add -g nuxi@latest
nuxi init <project-name>

By installing nuxi globally, you ensure that you have a permanent installation of the package on your system. You can then use the globally installed nuxi command to create a new project without relying on dlx.

However, keep in mind that global installations have some considerations:

  • Global installations are system-wide and can potentially conflict with other projects that may require different versions of the same package.
  • Updating the global package will affect all projects that depend on it, which may not always be desirable. Global installations can make it harder to manage and reproduce project-specific dependencies.

Local install:

pnpx nuxi@latest init <project-name>

This will download and execute the latest version of nuxi without installing it globally or adding it to your project's dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment