55

As the UmiJS documentation suggests, a project is created with the npm create command:

npm create umi

It seems to be working, but it's not documented.

Why did it appear and when? Is it a full synonym for npm init? Is there a reason why npm create should or should not be used?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Estus Flask
  • 206,104
  • 70
  • 425
  • 565

3 Answers3

77

It is an interesting question; I wasn't aware of this either.

To answer this question, I ran

npm create --help

which printed

npm init [--force|-f|--yes|-y|--scope] npm init <@scope> (same as npx <@scope>/create) npm init [<@scope>/] (same as npx [<@scope>/]create-<name>)

aliases: create, innit

So yes, it is a synonym, or more specifically an alias, for npm init.

This was done using npm 6.10.1.

It doesn't matter which command one uses, but init is the canonical form while create is an alias. This is evidenced by the fact that npm create --help actually invokes npm init --help which is why we see create listed as an alias in this above output.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84
  • Thanks for clarifying. I suspect this could be done to be coherent with `yarn create startername` usage but I haven't noticed before that both managers cared too much about compatibility. – Estus Flask Jul 21 '19 at 13:30
  • 1
    @EstusFlask yes, I suspect it's there for discoverability reasons. Actually, I just looked at Yarn and `create` and `init` are _not_ synonymous. – Aluan Haddad Jul 21 '19 at 13:35
  • 1
    Yes, it looks that Yarn separated them for some reason, similarly to install/add. – Estus Flask Jul 21 '19 at 13:45
3

npm create xyz is actually an undocumented shorthand for:

npx create-xyz

In other words, it prepends "create-" to the package name, temporarily installs that package, and then runs the script defined in the package.json. This is used by several projects. For the umi project, it implies there is a create-umi package as well, and as you can see there is:

create-umi

This is what the command is downloading and executing. Specifically it is executing the script defined in its package.json file:

  "bin": {
    "create-umi": "bin/create-umi.js"
  },

Many frameworks follow this pattern so you can use the command. Some others:

  • Svelte: npm create svelte@latest
  • Vue.js: npm create vue@latest
  • React: npm init react-app my-app
pabo
  • 625
  • 3
  • 14
Simon Sarris
  • 62,212
  • 13
  • 141
  • 171
0

npm create is a shorter way to use a tool that sets up a new project quickly. e.g: npm create umi creates a new project using the umi framework for building web applications. It saves time by generating a basic project structure and installing any necessary dependencies.

While npm init creates a new package.json file for a project, it does not generate a basic project structure. npm create is a user-friendly alternative that automates the process of setting up a new project. npm create is a useful shortcut for setting up a new project quickly, but it's important to note that not all Node.js packages support it. like : express

  • 3
    No, `npm create` is just an alias, as listed [here](https://github.com/npm/cli/blob/b1c3256d62250b5dca113dd99bf1bd99f2500318/lib/utils/cmd-list.js#L95C18-L95C18) – noobar Jul 16 '23 at 03:31