Freewind
Freewind

Reputation: 198318

How to restart a dart server which file changes?

I'm running a web server with dart, it starts by:

dart server.dart

When I modified the project files, I hope this server can be restarted automatically. Is there any way to do it? Or is there any useful tool can help?

Upvotes: 4

Views: 1483

Answers (3)

Shivanshu Gupta
Shivanshu Gupta

Reputation: 1

I'm a bit late answering this, but you can checkout this cli tool, to restart your server on file changes. (dartmon)

First install the cli using this command:

dart pub global activate dartmon_cli

And then run your server using simply by replacing dart with dartmon. For ex, you can run your server by entering any one command from the below list:

dartmon bin/main.dart
dartmon run dartmon bin/main.dart
dartmon run

Upvotes: 0

mmccabe
mmccabe

Reputation: 2309

Just ran into this problem developing a dart server. For vscode IDE, following this stackoverflow suggestion I installed the Save and Run Ext extension and modified it for a dart command line program:

{
  "saveAndRunExt": {
    "commands": [
      {
        // "match": "\\.(css$|js$|html$)",
        "match": ".dart$",
        "isShellCommand": false,
        "cmd": "workbench.action.debug.restart",
        "isAsync": false
      },
      {
        "match": ".dart$",
        "isShellCommand": false,
        "cmd": "dart.rerunLastTestDebugSession"
      }
    ]
  }
}

This will restart the server in debug mode and rerun the last test debug session if any dart file is saved. Both server and test debug sessions work. Works great for me, at least on initial use of this extension.

Upvotes: 0

Chris Buckett
Chris Buckett

Reputation: 14398

Not natively in Dart until bug 3310 is implemented. There may well be external tools that will restart the command line when a file changes (open to other answers).

Upvotes: 3

Related Questions