NodeJS 相关

多版本切换

  • 下载 nvm , window平台
  • 需要管理员权限,启动 Windows PowerShell 管理员模式
  • nvm install 指定版本npm:安装指定版本的 nodejs
  • nvm list :查看已经安装的 nodejs 版本
  • nvm use 指定版本
nvm install 14.0.0
nvm install 12.0.1
nvm use 14.0.0
npm install -g yarn
nvm use 12.0.1
npm install -g yarn

安装 yarn

  • npm install -g yarn

yarn 运行 vue3 项目

  • cd you project
  • yarn install
  • yarn serve

yarn install 报 The engine "node" is incompatible with this module 错误

  • yarn config set ignore-engines true

node js 用 child_process.spawn 运行 exe ,当路径中有空格时,会报错

  • 替换路径中的空格,代码为: value.replace(/" "./g, '"" ""')
  • 提醒,node js 版本里不一定有 replaceAll 方法,用 value.replace(/需要替换的内容./g, "替换后的内容") 替代,代码如下:
const spawn = require("child_process").spawn;

let cmdPath;
let workerProcess;
let mainWindow;
function runExec() {
  console.log("runExec cmdPath = " + cmdPath);
  workerProcess = spawn(cmdPath, { detached: true });
  workerProcess.on("spawn", function () {
    console.log("game running! " + workerProcess.pid);
  });

  workerProcess.on("error", function (err) {
    console.log("game launche error:");
    console.log(err);
  });

  workerProcess.on("close", function (code) {
    console.log("game close code:" + code);
  });
  workerProcess.on("exit", function (code) {
    console.log("game exit code:" + code);
    workerProcess = undefined;
  });
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容