Node.js Setup (包括设置国内镜像)

1, change to a mirror within the country 

 Set registry:

npm config set registry https://registry.npm.taobao.org

Verify:

npm config get registry

Install a local package:

npm install d3

2, check the node.js and npm version

npm --version
6.4.1
node --version
v10.15.1

3, using create-react-app

The following line installs a global package of "create-react-app" (a global package can be accessed anywhere from command line, and the package resides in the C:\Users\Administrator\AppData\Roaming\npm\node_modules folder):

npm install -g create-react-app

Check the "create-react-app" version:

扫描二维码关注公众号,回复: 5584888 查看本文章
create-react-app --version
2.1.5

 Create a new npm project named "graphics":

create-react-app graphics

4, uninstall a package:

Uninstall a local package:

npm uninstall d3

Uninstall a global package:

npm uninstall -g d3

5, install a local package with specific version

npm install -SE d3-selection

The "-SE" flag in the above line installs a package of "d3-selection" of a specific version (in this case, "1.4.0"):

"d3-selection": "1.4.0"

Why are we using the "-SE" flag? Why can't we be satisfied with just a plain old npm local installation? Because we don't want version incompatibilities when we share our package.json file. We want specific versions embedded in the package.json file so that others can install the exact same versions of the npm packages as the ones we are using.

So, when we are using "-SE" flag, we are not assuming automatic backward-compatibility. If backward compatibility is assumed, others could just install the latest versions (or edtions) of the packages without caring a damn about compatibility.

6, everyone can copy your project without the package dependencies, as long as they have the package.json file. 

Inside the project, you can use the following line to install the package dependency from the package.json file:

npm install

The script will scan over the entire dependencies in the package.json file and install them locally in your project.

猜你喜欢

转载自blog.csdn.net/qq_25527791/article/details/87524477