Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use npx instead of installing the CLI globally #2756

Open
1 task done
micalevisk opened this issue May 6, 2023 · 1 comment
Open
1 task done

Use npx instead of installing the CLI globally #2756

micalevisk opened this issue May 6, 2023 · 1 comment

Comments

@micalevisk
Copy link
Member

micalevisk commented May 6, 2023

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

since we will start supporting only node16 or greater in nestjs v10, I think it is a good time to start encourage devs to use npx as a good alternative to installing @nestjs/cli globally.

NPX is installed automatically with NPM version 5.2+ And looks like node16 comes with NPM v8 when we use NVM:

image

Then I'm confident that most people that are using node16 would also have NPX installed.

As of now, we got a hint on this already:

image

This is good because from time to time we got questions at our Discord server due to some mismatch between nest vs npx nest. Using the local @nestjs/cli is always better to me.

But I found that using npx @nestjs/cli@latest new could be tedious or too magic to new users or to folks that aren't used with npx.

Describe the solution you'd like

Others popular frameworks are using npm-init command (which has create as alias), like NextJS (npx create-next-app), SST (npm create sst) and Svelte (npm create svelte@latest myapp)

I'm proposing to change the https://docs.nestjs.com/cli/overview#installation page to replace npm install -g @nestjs/cli with npx create-nestjs (or npm create nestjs as we can use yarn create and pnpm create as well). And start using npx nest instead of nest on code snippets that are showing nest's CLI commands.

Teachability, documentation, adoption, migration strategy

We will need to touch the docs a bit.

Extra: an improvement to avoid installing the CLI globally

I've made the create-nestjs package with that in mind already and the code is tiny: https://github.com/micalevisk/create-nestjs/blob/main/run-nestjs-new.js It just call npx @nestjs/cli@latest new [...args] under the hood.

I could move that repository and change the onwership of that package to nestjs org if needed.

Thus we can already use those commands, see (linux):

demo-npm-create.webm
demo-yarn-create.webm
dem-pnpm-create.webm

What is the motivation / use case for changing the behavior?

  • Encourage the best practice of not installing @nestjs/cli globally as it will be available locally after bootstrapping a new nestjs app.
  • Reduce the amount of questions and GH Issues related with @nestjs/cli limitations on dealing with multiple versions of nestjs. And, sometimes, the issue is related with having other binary called nest on people's machine. This should be solved by telling them to use npx nest or yarn nest instead. They could also have an alias (like alias nest='npx nest') on their shell.
  • It might be more clear now that we won't have to upgrade a globally installed @nestjs/cli when upgrading one nestjs project since that package won't be global anymore.
@micalevisk
Copy link
Member Author

micalevisk commented May 6, 2023

Ideally, nest (global) should work with any version of nestjs installed locally but I don't think this is feasible.

@kamilmysliwiec kamilmysliwiec transferred this issue from nestjs/nest Jun 13, 2023
@kamilmysliwiec kamilmysliwiec changed the title nestjs v10 minor documentation change proposal: use npx instead of installing the CLI globally Use npx instead of installing the CLI globally Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant