There are lots of things, from downloading and using other’s packages, to sharing your own packages to the rest of the world, from making your (top secret projects) private and only shareable to people you choose (a.k.a for businesses), to managing multiple versions projects of code.
When it comes to the individual developer, there are lots of things you can do! The main things being
- Install && Manage dependencies:
- To install an npm package you would simple type (though this will change depending on the package, so make sure to consult their documentation):
- npm can install all the dependencies of a project / package (dependencies are any modules that are required by the npm package/project you install, to run: for example, in a random number generation game, the randomizer module is a dependency)
npm install <package>
- You can use it to share your own projects and packages to the world with the following steps:
- Sign up at https://www.npmjs.com
- Check if you are logged in with the
cmd: ‘npm whoami’command.
- If not, then log in first using the
cmd: ‘npm login’command
- After that, simply navigate to your project, using the command
cd <file path>and type into the terminal:
Alongside Npm comes a useful prepackaged tool called Npx, which is the second portion of this chapter.
Npx is basically an Npm package runner that helps you install and run any sort of node based executable that you would normally install using Npm.
Npx is an extremely handy tool as it allows you to run dependencies and packages without installing them.
Here’s a quick overview of the advantages of this:
Usually, packages and dependencies are installed either locally, for that project alone, or globally, for all user projects. However, sometimes, people don’t want to install packages using either of those methods, or sometimes people might only want to experiment with new packages and not want to install them into a project (and if the package isn’t to their liking, uninstalling it).
This is where Npx shines. Instead of having to install those packages, Npx will simply run them without having to fully install it, thereby saving disk space, and allows you to experiment all you want.
Npx scripts change according to the package, so to use it you need to consult the package