gpt4 book ai didi

node.js - 如何使用名称前没有 `node` 的 Powershell 执行 node.js 文件?

转载 作者:行者123 更新时间:2023-12-04 11:58:19 24 4
gpt4 key购买 nike

有没有办法从 Powershell 执行 node.js 文件,而无需在文件名前使用 node 调用文件?

例子:

现在我像这样执行它:node .\script.mjs.

我想只用名字来执行它:.\script.mjs.

怎么做?

最佳答案

您可以注册 .mjs 文件扩展名以默认使用 node.exe 打开。然后,您只需提供 .mjs 文件的路径即可调用 node。步骤:

  1. 右键单击任意 .mjs 文件
  2. 点击打开方式/打开方式...
  3. 点击选择另一个应用程序/更多应用程序↓ > 在这台电脑上寻找另一个应用程序
  4. 导航到您的 node.exe 文件
  5. 勾选始终使用此应用打开 .mjs 文件复选框
  6. 确定
  7. 确认

现在你可以在 CMD 或 PowerShell 中输入 .\script.mjs 来自动用 node 打开文件。

关于node.js - 如何使用名称前没有 `node` 的 Powershell 执行 node.js 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69423149/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com