Using npx vs installing frontity as a global package

What is the advantage of using always npx to execute frontity vs installing frontity as a global package?

Global packages in npm are quite bad to be honest.

  • They fail a lot because they are installed in a folder without user access, so people usually have to install them with sudo.
  • If you install them with sudo, they will create files and folders using sudo as the user, instead of the current user, which is a mess.

On the other hand, with npx:

  • If the package is not found in the current directory ./node_modules folder, npm will always download the latest version, which is really cool because npx frontity create will always use the latest starter themes and package versions.
  • If the package is found in the current directory ./node_modules folder, npm will use that package. This is also really cool because we want to match the command (i.e. npx frontity dev) to the code of the frontity package installed in that project. With global packages, you can have a mismatch.

I think npx is just a better solution.

By the way, if I’m not mistaken, the core commands like frontity dev don’t work right now when frontity is installed as a global package because the global package is on a different folder and it thinks it’s not on a Frontity project.

1 Like

Great explanation! Thanks @luisherranz