node.js基础包 npm操作练习
<?php
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
目录: E:\PHP学习\js学习
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2022-07-27 13:35 0722
d----- 2022-08-03 11:11 0802
PS E:\PHP学习\js学习> cd 0802
// ls 查看当前位置有哪些文档
PS E:\PHP学习\js学习\0802> ls
// cd 0802 进入到 0802文档
目录: E:\PHP学习\js学习\0802
Mode LastWriteTime Length Name
d----- 2022-08-03 10:39 node_modules
d----- 2022-08-03 11:11 npm
-a---- 2022-08-03 10:12 0 demo.js
-a---- 2022-08-03 10:09 274 demo1.html
-a---- 2022-08-03 10:39 782 package-lock.json
-a---- 2022-08-03 10:39 267 package.json
//查看node 版本信息
PS E:\PHP学习\js学习\0802\npm> node -v
v16.16.0
PS E:\PHP学习\js学习\0802\npm> clg
clg : 无法将“clg”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确
保路径正确,然后再试一次。
所在位置 行:1 字符: 1
+ clg
+ ~~~
+ CategoryInfo : ObjectNotFound: (clg:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS E:\PHP学习\js学习\0802\npm> node demo
throw err;
^
Error: Cannot find module 'E:\PHP学习\js学习\0802\npm\demo'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
// 生成默认的包和配置文件package.json
PS E:\PHP学习\js学习\0802\npm> npm init -y
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
Wrote to E:\PHP学习\js学习\0802\npm\package.json:
{
"name": "npm",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
PS E:\PHP学习\js学习\0802\npm> npm config set registry https://registry.npm.taobao.org
//将包 lodash 安装到本项目: npm i lodas
PS E:\PHP学习\js学习\0802\npm> npm i lodash
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
added 1 package in 4s
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
// 查看本项目路径: npm root
E:\PHP学习\js学习\0802\npm\node_modules
//查看全局路径: npm root -g
PS E:\PHP学习\js学习\0802\npm> npm root -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
C:\Users\asus\AppData\Roaming\npm\node_modules
PS E:\PHP学习\js学习\0802\npm> npm i axios -D -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
changed 8 packages in 2s
//查看安装的包(本项目)
PS E:\PHP学习\js学习\0802\npm> list
list : 无法将“list”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请
所在位置 行:1 字符: 1
+ list
+ ~~~~
+ CategoryInfo : ObjectNotFound: (list:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
//查看全局安装的包:npm list
PS E:\PHP学习\js学习\0802\npm> npm list
npm@1.0.0 E:\PHP学习\js学习\0802\npm
//查看全局安装的包:npm list -g
PS E:\PHP学习\js学习\0802\npm> npm list -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
C:\Users\asus\AppData\Roaming\npm
├── axios@0.27.2
├── lodash@4.17.21
└── ncu@0.2.1
PS E:\PHP学习\js学习\0802\npm> npm outdated
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code EEXIST
npm ERR! path C:\Users\asus\AppData\Roaming\npm\ncu
npm ERR! EEXIST: file already exists
npm ERR! File exists: C:\Users\asus\AppData\Roaming\npm\ncu
npm ERR! Remove the existing file and try again, or run npm
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\asus\AppData\Local\npm-cache\_logs\2022-08-03T03_58_47_449Z-debug-0.log
PS E:\PHP学习\js学习\0802\npm> ncu -u lodash
ncu : 无法加载文件 C:\Users\asus\AppData\Roaming\npm\ncu.ps1,因为在此系统上禁止运行脚本。有关详细信息,请
参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ ~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
PS E:\PHP学习\js学习\0802\npm> npm list -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
├── axios@0.27.2
├── lodash@4.17.21
└── ncu@0.2.1
//删除已安装的全局的包 ncu
PS E:\PHP学习\js学习\0802\npm> npm uninstall ncu -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
removed 75 packages, and audited 1 package in 1s
found 0 vulnerabilities
PS E:\PHP学习\js学习\0802\npm> npm list -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
C:\Users\asus\AppData\Roaming\npm
├── axios@0.27.2
└── lodash@4.17.21
PS E:\PHP学习\js学习\0802\npm> npm uninstall lodash -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
removed 1 package, and audited 1 package in 2s
PS E:\PHP学习\js学习\0802\npm> npm list -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
C:\Users\asus\AppData\Roaming\npm
PS E:\PHP学习\js学习\0802\npm> npm list
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm@1.0.0 E:\PHP学习\js学习\0802\npm
└── lodash@4.17.21
//将更新插件安装到全局 ncu:npm-check-updates
PS E:\PHP学习\js学习\0802\npm> npm i npm-check-updates -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
added 280 packages in 14s
PS E:\PHP学习\js学习\0802\npm> npm list -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
C:\Users\asus\AppData\Roaming\npm
├── axios@0.27.2
└── npm-check-updates@16.0.5
PS E:\PHP学习\js学习\0802\npm>
?>