2016-02-06 90 views
10

我使用Visual Studio代碼作爲NodeJS項目的編輯器。VSCode編輯器 - 更改文件時重新啓動NodeJs服務器

目前我需要在我的項目中更改文件時手動重新啓動服務器。

當我在文件中進行更改時,VSCode中是否存在任何可以自動重新啓動NodeJS服務器的插件或配置更改。

+0

與運行腳本['nodemon'(https://www.npmjs.com/package/nodemon),而不是' node'。 – Shanoor

+1

'nodemon'和'node-dev'都不能用於VSCode。一旦它終止了進程,調試器會認爲它已經死機並關閉。 –

+0

看起來有一個功能請求:https://github.com/Microsoft/vscode/issues/2103 –

回答

0

使用pm2看你的代碼,並自動重新啓動

npm install pm2 -g 
npm install pm2 

process.json

{ 
    name  : "App", 
    script  : "app.js", 
    watch  : true, 
} 

你可以找到演示@ https://github.com/sivasankars/jade-title-rendering

+0

@Teomanshipahi手段? –

+0

@Teomanshipahi更新:) –

+0

酷,它現在的作品。謝謝! –

9

現在,您可以使用Nodemon VS Code來實現這一點。我今天測試了支持VS Code的Nodemon,它對我很好。以下是我的VS代碼細節。

  • 版本:1.9.1
  • 提交:f9d0c687ff2ea7aabd85fb9a43129117c0ecf519
  • 日期:2017-02-09T00:26:45.394Z
  • 殼牌:1.4.6
  • 渲染:53.0.2785.143
  • 節點:6.5.0

我安裝了Nodemon全球npm install -g nodemon和創建VS代碼的啓動配置如下

{ 
    "name": "Nodemon Launch Server", 
    "type": "node", 
    "request": "launch", 
    "cwd": "${workspaceRoot}", 
    "runtimeExecutable": "nodemon", 
    "runtimeArgs": [ 
     "--debug=5858" 
    ], 
    "program": "${workspaceRoot}/server.js", 
    "restart": true, 
    "port": 5858, 
    "console": "integratedTerminal", 
    "internalConsoleOptions": "neverOpen" 
    } 

參考:https://code.visualstudio.com/docs/editor/node-debugging#_restarting-debug-sessions-automatically-when-source-is-edited

0

您還可以安裝nodemon本地npm install nodemon --save-dev

和VS代碼launch.json的配置,下面的例子:

[ 
    { 
    "name": "Nodemon", 
    "type": "node", 
    "request": "launch", 
    "runtimeExecutable": ${workspaceFolder}/node_modules/nodemon/bin/nodemon.js", 
    "program": "${workspaceFolder}/src/server/index.js", 
    "restart": true, 
    "console": "integratedTerminal", 
    "internalConsoleOptions": "neverOpen" 
    } 
] 
相關問題