Câu hỏi phỏng vấn Nodejs
Câu hỏi

Explain the difference between local and global npm packages installation

Câu trả lời

The difference between local and global npm package installations lies primarily in their scope and accessibility within the file system.

Local Installation

  • Scope: Local packages are installed in the directory where the npm install <package-name> command is executed.
  • Location: They are placed in the node_modules folder within that directory[3].
  • Project-Specific: Local packages are intended for use within a specific project. Each project can have its own version of a package, avoiding version conflicts between projects[1][3].
  • Accessibility: Locally installed packages are accessible only within the project. They can be required in the project's code using require('package-name')[3].
  • Command-Line Execution: If a locally installed package includes an executable command, it is not directly available in the system path. However, it can be run using the path ./node_modules/.bin/<command> or by defining scripts in the package.json file[4].

Global Installation

  • Scope: Global packages are installed system-wide and are not tied to any particular project directory.
  • Location: They are stored in a central location that varies based on the system setup, but it's typically a designated npm installation directory[3].
  • System-Wide Use: Global packages are generally command-line tools or utilities that are meant to be used across multiple projects[1].
  • Accessibility: Once installed globally, the package's executables are available from any directory in the system, as they are added to the ...
junior

junior

Gợi ý câu hỏi phỏng vấn

middle

Provide some of the reasons not to use Node.js

middle

Explain how does Node.js work?

junior

What are the key features of Node.js?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào