Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

desktop-service

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

desktop-service

Run Node.js scripts as native services on Windows, Mac OS and Linux.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
increased by30.77%
Maintainers
1
Weekly downloads
 
Created
Source

desktop-service

Run Node.js scripts as native services on Windows, Mac OS and Linux.

Usage

var Service = require('desktop-service');

var svc = new Service({
  name: 'Sample Service',
  description: 'Sample service running Node.js script.',
  script: require('path').join(__dirname, 'service.js'),
});

svc.on('install', function () {
  svc.start();
});

svc.install();

After the installation the service will be listed like any other service in the service management utility of the OS.

Sample Service listed in the Services utility on Windows

Environment Variables

Sometimes you may want to provide a service with static data, passed in on creation of the service. You can do this by setting environment variables in the service config, as shown below:

var svc = new Service({
  name: 'Sample service',
  description: 'Sample service running Node.js script.',
  script: require('path').join(__dirname, 'service.js'),
  env: [
    {
      name: 'HOME',
      value: process.env['USERPROFILE'], // service is now able to access the user who created its home directory
    },
    {
      name: 'TEMP',
      value: path.join(process.env['USERPROFILE'], '/temp'), // use a temp directory in user's home directory
    },
  ],
});

Uninstalling a Service

var Service = require('desktop-service');

var svc = new Service({
  name: 'Sample Service',
  script: require('path').join(__dirname, 'service.js'),
});

svc.on('uninstall', function () {
  console.log('Uninstall complete.');
  console.log('The service exists: ', svc.exists);
});

svc.uninstall();

Note that the uninstall process only removes process-specific files. It does not delete your Node.js script.

Keywords

FAQs

Package last updated on 19 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc