Nodejs CLI And Npm CLI

Level : Beginner
Mentor: Shailendra Chauhan
Duration : 00:09:00

What is Node.js CLI?

CLI, or Command Line Interface, is the primary means of interfacing with computer programs via text-based commands. It allows users to give instructions directly to the system, making control and operation more efficient. CLI can manage node command line arguments, allowing for exact task configuration and execution within a program or system.

CLI Options

Node.js includes several CLI options that are used for:

  • Debugging
  • Execute scripts
  • Other useful runtime options

Node CLI Commands

  • node -v, node --version: Prints the Node.js version.
  • node -h, node --help: Print the Node.js command line arguments.
  • node -e "script", node --eval "script": Evaluate the specified JavaScript script using REPL preset modules.
  • node -p "script", node --print "script": Run the provided JavaScript script and print the results.
  • node -c, node --check: Check the script's syntax without executing it.
  • node -i, node --interactive: Open the REPL (Read-Eval-Print Loop), even if stdin does not appear to be terminal.
  • node -r module; node --require module: Use the resolution criteria for require() to preload the specified module at startup.
  • node --no-deprecation: Disable deprecation warnings.
  • node --trace-deprecation: Output stack traces for deprecations.
  • node --throw-deprecation: Return errors for deprecations.
  • node --no-warnings: Disables all process warnings, including deprecation.
  • node --trace-warnings: Display stack traces of process warnings, including deprecations.
  • node --trace-sync-io: Print a stack trace whenever synchronous I/O is detected after the event loop's first turn.
  • node --zero-fill-buffers: Automatically zero-fill all freshly allocated buffer and slow buffer instances.
  • node --track-heap-objects: Monitor heap object allocations for heap snapshots.
  • node --prof-process: Process the V8 profiler output supplied with the --prof option.
  • node --v8-options: Print V8's command line options.
  • node --tls-cipher-list=list: Set an alternate default TLS cipher list.
  • node --enable-fips: Enable FIPS-compliant crypto during setup.
  • node --force-fips: Enforce FIPS-compliant crypto upon startup.
  • node --icu-data-dir=file: Specifies ICU data load path, overriding node_icu_data.

What is NPM?

NPM stands for Node Package Manager. It's an online repository for node packages. In 2011, open-source libraries like as jQuery, AngularJS, and React were shared and updated. 

What is NPM CLI?

The term "npm CLI" refers to the Node Package Manager, whereas "CLI" refers to the Command Line Interface. Using the command line, we try to access NodeJS's packages and dependencies. npm CLI offers developers a variety of features for installing, deleting, and managing projects.

NPM CLI Commands

  • npm access: Set access level for published packages.
  • npm adduser: Create a registry user account.
  • npm audit: Conduct a security audit.
  • npm bugs: To get bugs from a package, use a web browser or the npm cache.
  • npm cache: Manipulates package cache.
  • npm ci: Install a project on a clean slate.
  • npm completion: Enable tab completion for npm.
  • npm config: Manage npm configuration files.
  • npm dedupe: Reduce duplication of installed packages.
  • npm deprecate: Deprecate a package version.
  • npm diff: Show the distinction between two versions of a package.
  • npm dist-tags: Modify the package distribution tags.
  • npm docs: To access package documentation, use a web browser.
  • npm doctor: Check your environments for any issues.
  • npm edit: Edit an installed package.
  • npm exec: Use a command from a npm package.
  • npm explain: Explain the installed packages.
  • npm explore: Browse an installed package.
  • npm find-dupes: Find duplicates in the package tree.
  • npm fund: Retrieve financing data for packages.
  • npm help: Search the npm help documentation.
  • npm help-search: Get help with npm topics.
  • npm hook: Manage registry hooks.
  • npm init: Create the package.json file.
  • npm install: Install the package.
  • npm install ci-test: Install a project from scratch and run tests.
  • npm install test: Install packages and run tests.
  • npm link: Symlink a package folder.
  • npm login: Log into a registry user account.
  • npm log out: Log out of the registry.
  • npm ls: List the installed packages.
  • npm org: An org management tool.
  • npm outdated: Review for outdated packages.
  • npm owner: Handle package owners.
  • npm pack: Generates a tarball from a package.
  • npm ping: Ping the npm registry.
  • npm pkg: Controls your package.json.
  • npm prefix: Display the prefix.
  • npm profile: Edit your registry profile.
  • npm prune: Remove any superfluous packages.
  • npm publish: Create a package.
  • npm query: Get a filtered list of packages.
  • npm rebuild: Rebuilds a package.
  • npm repo: Open the package repository page in your browser.
  • npm restart: Restart the package.
  • npm root: This displays the npm root.
  • npm run-script: Executes arbitrary package scripts.
  • npm sbom: Create a Software Bill of Materials (SBOM).
  • npm search: Search for packages.
  • npm shrinkwrap: Lock down the dependency versions for publication.
  • npm star: Mark your favorite packages.
  • npm stars: View packages marked as favorites.
  • npm start: Start a package.
  • npm stop: Stop a parcel.
  • npm team: Manage organizational teams and their memberships.
  • npm test: Test a package.
  • npm token: Manage your authentication tokens.
  • npm uninstall: Remove a package.
  • npm unpublish: Uninstall a package from the registry.
  • npm unstart: Remove an item from your favorite bundles.
  • npm update: Update a package.
  • npm version: Update a package version.
  • npm view: View registry information.
  • npm whoami: Display the npm username.
  • npx: Execute a command from a npm package

NPM CLI Features

  • Installing, removing, updating, and listing packages are all done using it (Package Management)
  • It is used to start and manage a project (Project Management).
  • It uses package-lock.json to assure uniformity in Node projects.
  • It offers enhanced security features. The 'npm audit' command scans for vulnerabilities and fixes them regularly.

Benefits of the NPM CLI

  • The npm cli provides a faster way to install or create projects.
  • Package installation takes less time.
  • It enables the developer to customize the changes that are needed.

What are Local Packages?

Local packages are configured at the project level. These are installed in the node_modules subdirectory of the parent working directory (project-level folder).

What are Global Packages?

Global packages are installed in a global location. In Windows OS, the global location is /users/username/AppData/Roaming/npm/node_modules.

Difference between local and global packages

The most important difference between local and global packages is this:

  • Local packages are installed in the directory where you execute npm install <package-name>. They are placed in the node_modules subdirectory under this directory.
  • Regardless of where you run npm install -g <package-name>, all global packages are stored in a single location on your system (the actual location depends on your setup).

Various options to download the version of a node module

Update Packages

To update a node package, use the following command.

  • npm update angular

You can also update global packages by passing the -g option to commands

  • npm update angular -g

Uninstalling packages

To uninstall or remove a node package, use the two instructions shown below.

  • npm uninstall angular
  • npm rm angular

You can also uninstall global packages by using the -g option in commands.

  • npm uninstall angular -g
  • npm rm angular -g

What is Module?

A module is a JavaScript collection that combines related code into a single unit of code. To load a JavaScript library or module into your program, use the require() method.

Core Modules in Node.js

  • Buffer: A module for managing binary data.
  • Console: A module for debugging and logging.
  • Crypto: A module for cryptographic operations.
  • Debugger: A module for debugging Node.js apps.
  • Events: Module for event management.
  • File System: A module for file operations.
  • Http: A module for developing HTTP servers and clients.
  • Net: A module for developing networking applications.
  • OS: A module that interacts with the operating system.
  • Vm: A module for executing code within a virtual machine.
  • Path: A module for dealing with file paths.
  • Process: A module for communicating with the running Node.js process.
  • Query String: A module for processing and formatting query strings.
  • Timers: A module for scheduling tasks.
  • Urls: A module for URL processing and formatting.
  • Zlib: A module for compression and decompression.
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
Accept cookies & close this