npm等命令行工具安装
npm工具软件安装
使用nvm(node版本管理工具)安装
https://github.com/nvm-sh/nvm
https://github.com/coreybutler/nvm-windows
nvm-windows找到nvm的安装目录settings.txt文件
添加或修改以下两行
node_mirror: https://npmmirror.com/mirrors/node/
npm_mirror: https://npmmirror.com/mirrors/npm/
nvm-sh
echo 'export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node' >> ~/.bashrc
echo 'export NVM_IOJS_ORG_MIRROR=https://npmmirror.com/mirrors/iojs' >> ~/.bashrc
source ~/.bashrc
nvm --version # 查看 nvm 自身版本
nvm list # 列出本地已安装的 Node.js 版本
nvm list available # Windows:查看可安装的版本列表
nvm current # 显示当前正在使用的 Node.js 版本
nvm install 18 # 安装最新 18.x 版本(如 18.20.4)
nvm install 18.17.0 # 安装指定小版本
nvm uninstall 16.20.0 # 卸载指定版本
nvm use 18 # 临时切换到 Node.js 18(当前终端会话有效)
nvm use 16.20.0 # 切换到具体版本
nvm alias default 18 # 设置默认版本(新终端自动使用)
nvm alias default lts # 设为默认 LTS
验证是否安装成功
node -v
npm -v
npm切换镜像源
查看当前使用镜像源
npm config get registry
查看是否设置了代理
npm config get proxy
切换到淘宝镜像源
npm config set registry https://registry.npmmirror.com/
使用nrm工具切换镜像
安装nrm工具
npm install nrm -g
查看可以切换的镜像
nrm ls
测试镜像连接速度
nrm test
建议切换使用taobao镜像
切换为taobao镜像
nrm use taobao
全局安装代码js压缩工具 uglify-js
npm全局安装
npm install uglify-js -g
js文件执行压缩操作
uglifyjs fileinput.js -o fileinput.min.js
全局安装代码css压缩工具 uglifycss
npm全局安装
npm install -g uglifycss
css文件执行压缩操作
uglifycss fileinput.css --output fileinput.min.css
npm全局安装查看卸载操作
查看已全局安装的包(不包括它们的依赖)
npm list -g --depth=0
全局安装包
npm install -g <package-name>
全局卸载包
npm uninstall -g <package-name>
升级单个全局包
npm update -g <package-name>
更可靠的方式是先卸载再安装
npm uninstall -g <package-name>
npm install -g <package-name>
或者直接重新安装(npm 会自动安装最新版本)
npm install -g <package-name>@latest
全局包安装位置
npm root -g
iflow cli安装
iflow cli安装
npm i -g @iflow-ai/iflow-cli@latest
手动更新
npm i -g @iflow-ai/iflow-cli to update
卸载
npm uninstall -g @iflow-ai/iflow-cli
重新安装
npm i -g @iflow-ai/iflow-cli
启动iFlow
iflow
node脚本对当前目录下文件进行\n换行转换
// 使用方法:node tmpzhuanhuan.js
// tmpzhuanhuan.js
const fs = require('fs');
const path = require('path');
const TARGET_EOL = '\n'; // 改为 '\r\n' 则转为 CRLF
const EXTENSIONS = ['.js', '.ts', '.json', '.md', '.html', '.css', '.txt'];
function walk(dir) {
let results = [];
const list = fs.readdirSync(dir);
list.forEach(file => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat && stat.isDirectory()) {
results = results.concat(walk(filePath));
} else if (EXTENSIONS.includes(path.extname(file).toLowerCase())) {
results.push(filePath);
}
});
return results;
}
const files = walk('.');
files.forEach(file => {
try {
let content = fs.readFileSync(file, 'utf8');
// 统一替换为指定换行符
content = content.replace(/\r\n|\r|\n/g, TARGET_EOL);
fs.writeFileSync(file, content, 'utf8');
console.log('Converted:', file);
} catch (err) {
console.warn('Skip binary or unreadable file:', file);
}
});
console.log(`✅ 已转换 ${files.length} 个文件为 ${TARGET_EOL === '\n' ? 'LF' : 'CRLF'} 换行符`);