[solid foundation of vue.js] nodejs introduction npm cnpm installation and uninstallation module

Posted by hooch_au78 on Tue, 18 Jan 2022 21:43:52 +0100

nodejs understanding

Just as java needs a jvm virtual machine to run, js execution can be executed in the browser. Usually, we execute through the chrome console command window, that is, the browser supports js operation. nodejs is such a platform that can run js without the browser

node is a javascript running environment (platform) used to develop server-side applications and web systems. It is characterized by small volume, high speed and high performance.

node is a javascript runtime given to Google v8 engine, which can be understood as a virtual machine running js
. He uses an event driven, non blocking I/O model. He moves the running environment of js to the server side

Node is actually divided into two parts. One is to encapsulate the v8 engine in order to execute es (such as defining variables and functions). The other provides a large number of tool libraries to help node realize various functions and provide some things that could not be done in the previous js environment, such as file operation, network operation and operating system operation.
JavaScript is composed of ecmascrip language, BOM and Dom, Dom and BOM (API opened by browser)

npm introduction

npm is the package management tool of JavaScript. Similar to maven and gradle in Java syntax

nodejs installation

For the installation tutorial, see - > Reference tutorial
npm is integrated in the new nodejs. As long as nodejs is successfully installed, npm should also be successfully installed. Enter npm -v in cmd to view the version number of npm.

Modify the cache directory and global directory path of NPM

npm config set prefix "D:\nodejs\node_global"   //Configure global module storage path
npm config set cache "D:\nodejs\node_cache"   //cache path


C:\Users\Hua>npm config get prefix
D:\nodejs\node_global

Configure environment variables for npm and nodejs

Test whether the configuration is successful

Open cmd, enter node, enter, and then enter require('cluster '). If the information of the cluster module can be output normally, it means that all the above configurations are effective.

C:\Users\Hua>node
Welcome to Node.js v16.13.1.
Type ".help" for more information.
> require('cluster')
EventEmitter {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  isWorker: false,
  isMaster: true,
  isPrimary: true,
  Worker: [Function: Worker],
  workers: {},
  settings: {},
  SCHED_NONE: 1,
  SCHED_RR: 2,
  schedulingPolicy: 1,
  setupPrimary: [Function (anonymous)],
  setupMaster: [Function (anonymous)],
  fork: [Function (anonymous)],
  disconnect: [Function (anonymous)],
  [Symbol(kCapture)]: false
}

Reset the registration, management and publishing address of npm module to cnpm:

pm install cnpm -g
npm install -g cnpm --registry=https://registry.npm.taobao.org

Modify the registry of npm package manager to Taobao image

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

View nodejs npm cnpm version

C:\Users\Hua>node -v
v16.13.1

C:\Users\Hua>npm -version
8.1.2

C:\Users\Hua>cnpm -v
cnpm@7.1.0 (D:\nodejs\node_global\node_modules\cnpm\lib\parse_argv.js)
npm@6.14.15 (D:\nodejs\node_global\node_modules\cnpm\node_modules\npm\lib\npm.js)
node@16.13.1 (D:\Program Files\nodejs\node.exe)
npminstall@5.3.1 (D:\nodejs\node_global\node_modules\cnpm\node_modules\npminstall\lib\index.js)
prefix=D:\nodejs\node_global
win32 x64 10.0.19042
registry=https://registry.npmmirror.com

Installing and uninstalling modules using npm

npm install vue --save    # --save: download the vue package to the current directory
$ npm install jquery --save    
$ npm install webpack --save-dev 

npm uninstall cnpm -g

Topics: Javascript node.js npm Vue Vue.js