What are the main similarities between the two?
Both npm and cargo are used by developers to install dependencies into their projects, providing additional utility or convencience to the developer. Instead of having to build large libraries, a developer can install a package and use the pre-written functionality.
Are there any significant differences?
Cargo and npm are mostly the same, however cargo is a test/benchmark runner and also has a number of features out of the box which donβt exist with npm; for example workspaces. Workspaces are created where one or more packages share dependencies.
Cargo also has dependency overrides.
What is the equivalent of cargo new in the npm world?
In npm, a developer will use the command npm init project-name
to create a new node project, as cargo new project-name
would be used with cargo.
What is the equivalent of package.json in the cargo world?
In cargo, the Cargo.toml file represents the packages tracks some of the project metadata and holds the details of the packages, much like package.json does for npm
What is the equivalent of cargo run in the npm world?
The command cargo run
will build and execute the target file which is output from the cargo build
command.
This is similar to npm run build
, npm run prod
, npm run dev
or npm run start
depending on whether the developer wishes to have hot module reloading and efficiently built project.
The closest comparison would be between cargo run
and npm run build
and then npm run prod
.