◆ 模塊作用:
nodemon是一個命令行工具,用以輔助項目開發。在Node.js中,可以在每次修改文件後重新執行該文件。
◆ 使用步驟:
- 使用npm install nodemon –g 下載
F:\workstation\nodejs> npm install nodemon -g
- 在命令行工具中用nodemon命令替代node命令執行文件
F:\workstation\nodejs> nodemon .\demo.js
[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node .\demo.js`
測試代碼
[nodemon] clean exit - waiting for changes before restart
◆ nodemon執行報錯處理:
報錯信息:
F:\workstation\nodejs> nodemon .\demo.js
nodemon : 無法加載文件 C:\Users\ASUS\AppData\Roaming\npm\nodemon.ps1,因爲在此係統上禁止運行腳本。有關詳細信息,請參閱
https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ nodemon .\demo.js
+ ~~~~~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
解決方案:
管理員身份打開powerShell,輸入set-ExecutionPolicy RemoteSigned,選擇Y或者A。
F:\workstation\nodejs> set-ExecutionPolicy RemoteSigned
執行策略更改
執行策略可幫助你防止執行不信任的腳本。更改執行策略可能會產生安全風險,如 https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies 幫助主題所述。是否要更改執行策略?
[Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暫停(S) [?] 幫助 (默認值爲“N”): Y