Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The method for making Deno's standard http fileserver monitor files is by using the watchFileSystem option. Here's an example of how to use the fileserver and watchFileSystem options together:

import { serve } from 'https://deno.land/std/http/server.ts';
import { fileServer } from 'https://deno.land/std/http/file_server.ts';

const server = serve({ port: 8000 });

// Serving files
for await (const req of server) {
  // The root directory being served
  const root = './public';

  // Enable file watching and automatic refresh
  const fileServerConfig = { 
    ...fileServer(root), 
    watchFileSystem: true 
  };

  // Serve files with the file server
  const requestHandler = fileServer(fileServerConfig);
  requestHandler(req);
}

In this example, the file_server will watch the file system for changes and automatically refresh the served files when a change is detected. The watchFileSystem option is set to true to enable this behavior.