<p dir="auto">Would love to have a better web development experience with Deno out of the box.</p>
<ul dir="auto">
<li>First, the server should restart whenever I make changes.</li>
<li>Second, the website should reload whenever I make changes.</li>
</ul>
<p dir="auto">For the server, I'd like to propose a <code class="notranslate">deno watch</code> subcommand or <code class="notranslate">deno run --watch</code> flag that automatically restarts the server in a controlled way, e.g.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="deno watch *.ts --run main.ts --allow-net
# or
deno run --watch *.ts --allow-net main.ts"><pre class="notranslate"><code class="notranslate">deno watch *.ts --run main.ts --allow-net
# or
deno run --watch *.ts --allow-net main.ts
</code></pre></div>
<p dir="auto">If we also had a <code class="notranslate">Deno.watch</code> API for watching directories or files, we could then implement a simple client refresh via <a href="https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events" rel="nofollow">server-sent events</a> (<a href="https://gist.github.com/MarkTiedemann/1c43c42792825d2a86f88bbd52f55a5a">example</a>) or web sockets.</p>
<p dir="auto">EDIT: It would be nice if the <code class="notranslate">watch</code> subcommand/flag would be able to notify the running code that it will/should be restarted - maybe something via signals (e.g. <code class="notranslate">SIGUSR1</code>), command line flags, some API, or a similar mechanism - so that the server could notify the client that it will be restarted and that the client needs to be reloaded.</p>
<p dir="auto">There are several use cases where the ability to watch a file(s) for changes is an important API.  For example, invalidating cache headers for serving static file based content, or processing logs or files, etc.</p>
<p dir="auto">Many OSes provide a mechanism for this without having to "poll" the stats for the file.  Node.js offers <a href="https://nodejs.org/docs/latest/api/fs.html#fs_fs_watch_filename_options_listener" rel="nofollow"><code class="notranslate">fs.watch()</code></a>.</p>
<p dir="auto">Instead of an event listener though, it feels some sort of async generator would be more idiomatic to the rest of Deno.</p>