Home  >  Article  >  Web Front-end  >  How to use npm command to install jquery

How to use npm command to install jquery

PHPz
PHPzOriginal
2023-04-07 09:25:053899browse

With the continuous development of front-end development technology, jQuery, as a lightweight JavaScript library, is well known and widely used by thousands of developers. In order to use jQuery conveniently and quickly, this article will show you how to install jQuery through the npm command.

1. Introduction to npm

npm (node ​​package manager) is a node.js package management tool, used to manage node.js modules. With npm, we can easily install and upgrade various modules and libraries, thus greatly improving the efficiency of front-end development.

2. How to install jQuery with npm

1. Open the command prompt (Windows system) or terminal (Mac/Linux system) and enter the following command to install globally:

npm install jquery -g

2. After pressing the Enter key, npm will start installing jQuery. During the installation process, npm will automatically download the jQuery compressed package from npm's official server and extract it to the global installation directory.

3. After the installation is complete, we can enter the following command in the command prompt or terminal to view the jQuery version:

jquery -v

4. If the installation is successful, the command prompt or terminal will return to the current The version number of jQuery installed.

3. How to use jQuery with npm

1. In projects that need to use jQuery, we can use the following command to install jQuery in the current directory:

npm install jquery --save

2. After pressing the Enter key, npm will automatically download the jQuery compressed package from npm's official server, decompress it to the current project directory, and add jQuery to the package.json file of the current project. dependencies.

3. When using the jQuery library in a project, you only need to add the following code to the page that needs to be referenced:

<script src="./node_modules/jquery/dist/jquery.min.js"></script>

4. After adding the reference, you can use it on the page Various functions of jQuery.

4. Summary

Installing jQuery through the npm command can eliminate various issues such as downloading and installation compatibility in front-end development. The installation process is simple and convenient, and it is also beneficial to project management. Dependencies of various libraries. When using jQuery in a project, you only need to add references to important js files, which is very convenient. If you are a front-end developer, don’t miss this tool, it will make you get twice the result with half the effort in development.

The above is the detailed content of How to use npm command to install jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn