简体   繁体   English

如何制作Windows 10安装文件

[英]How to make a windows 10 install file

I want to know if Windows offers an installation script or tool to install node runtime and my node js code.我想知道 Windows 是否提供安装脚本或工具来安装节点运行时和我的节点 js 代码。

This is what I want to:这就是我想要的:

  • install node安装节点
  • download the compiled node app下载编译好的节点应用
  • use pm2 to run the code like node app.js使用pm2运行node app.js类的代码
  • make this as a window service and starts on boot将此作为窗口服务并在启动时启动

The can download this installation file.可以下载这个安装文件。 Click on it once, all this will run.单击一次,所有这些都会运行。 Like a bat file or power shell script.像 bat 文件或 power shell 脚本。

I did not test this extensively, but it should at least give you some ideas for getting started.我没有对此进行广泛的测试,但它至少应该为您提供一些入门的想法。

  • Use Invoke-WebRequest to download the Node.js Windows installer使用Invoke-WebRequest下载 Node.js Windows 安装程序
  • Use Start-Process and msiexec.exe to install it使用Start-Processmsiexec.exe安装它
  • With Node.js installed, you should be able to use npm to install the latest version of PM2安装 Node.js 后,您应该可以使用npm安装最新版本的 PM2
  • Use Invoke-WebRequest again to download the Node app file再次使用Invoke-WebRequest下载 Node 应用程序文件
  • Instead of a custom Windows service, consider creating a scheduled task that runs at logon with New-JobTrigger and Register-ScheduledJob考虑使用New-JobTriggerRegister-ScheduledJob创建一个在登录时运行的计划任务,而不是自定义 Windows 服务
Invoke-WebRequest -Uri "https://nodejs.org/dist/v14.17.1/node-v14.17.1-x64.msi" -OutFile ".\node-v14.17.1-x64.msi"
Start-Process msiexec.exe -Wait -ArgumentList "/i node-v14.17.1-x64.msi /quiet"

npm install pm2@latest -g

Invoke-WebRequest -Uri "node-app-url" -OutFile ".\app.js"

$trigger = New-JobTrigger -AtLogOn -RandomDelay "00:00:30"
Register-ScheduledJob -Trigger $trigger -ScriptBlock { pm2 start app.js } -Name "RunNodeAppAtLogon"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM