Skip to main content

Windows Service for Deno

A Deno library that provides a simple way to create Windows services using Deno applications without any external tools.


  • Run Deno applications as Windows services
  • React to events like “stop”, “pause”, and “continue” from the Windows Service Manager


To use the windows-service library in your project, add the following import statement:

import { WindowsService } from ""


// Create a new WindowsService instance
const service = new WindowsService("MyDenoServiceWithCallbacks")

// Define the main function for your service
async function main() {
  console.log("Service started.")
  // Your service logic here...

// This is a request from the SCM to stop the service
service.on("stop", () => {
  // Do stuff ...

  // Do stop the service
  // - This is done automatically if no handler for 'stop' event is defined.
  //   But included here for demonstration.

// Start the service, pass the main function

For more details and examples, please refer to the example implementation.

Install the service with

sc.exe create my-test-service binPath= "c:\full\path\to\deno.exe run" -A --unstable --allow-ffi "C:/path/to/windows-service/example.ts"

Or compile it using

deno compile -A --unstable --allow-ffi example.ts --include dispatcher.js --output my-test-service.exe

And install using

sc.exe create my-test-service binPath= "C:/path/to/windows-service/my-test-service.ts"

Note that dispatcher.ts need to be included using --include at compile time, else the service worker wont work.

Note Both –unstable and –allow-ffi is required at the moment

Using run.ts as a Generic Service Runner

You can use the run.ts file as a generic service runner without downloading or installing anything. The file accepts command-line arguments for the service name, the --debug flag, and the command to run with its arguments after --.

To run the generic service runner with a command:

deno run -A --allow-ffi --unstable --serviceName your-service -- your_command your_arguments

If you want to debug (execute the command directly without the Windows service part), pass the --debug flag:

deno run -A --allow-ffi --unstable your_script.ts --serviceName your-service --debug -- your_command your_arguments

To install a service using this library and a generic command

sc.exe create your-service binPath= "c:/full/path/to/deno.exe run -A --unstable --allow-ffi --serviceName your-service -- your_command your_arguments"


This project is licensed under the MIT License. See for more details.