3.0.3 • Published 7 years ago

node-autostart v3.0.3

Weekly downloads
17
License
MIT
Repository
github
Last release
7 years ago

node-autostart

Build Status Build status Coverage Status Dependency Status devDependency Status npm

node-autostart is a Node.js module that enables your module to activate autostart easily. You can also use it as a global module to set-up autostart for anything and anywhere via the command line interface (CLI). Currently, it supports:

  • Linux
  • OS X
  • Windows

Install:

npm install -g node-autostart

for use in CLI, and:

npm install --save node-autostart

as a dependency for your module.

Documentation

You can use node-autostart both programmatically and per CLI. 'Enabling autostart' means to make the OS run a certain command at logon of the user who 'enabled the autostart' via a program. The command could be, for example, npm start in a certain directory, or whatever floats your boat. Here's an example for use via the CLI:

  autostart enable -n "MyAwesomeApp" -p "/home/me/MyAwesomeApp" -c "npm start"

to enable,

  autostart check -n "MyAwesomeApp"

to see if it is enabled, and:

  autostart disable -n "MyAwesomeApp"

to disable it. To use it inside your Node.js app, look at the API for Programmatic Use, if you want to use it in the CLI, use autostart -h for further information.

API for Programmatic Use

First, require this module inside your app like this:

var autostart = require('node-autostart')

Now, you can simply enable autostart and disable it, and you can also check if it is enabled:

autostart.enableAutostart(key, command, path, function (err) {
  if(err) console.error(err);
})

autostart.disableAutostart(key, function (err) {
  if(err) console.error(err);
})

autostart.isAutostartEnabled(key, function (err, isEnabled) {
  if(err) console.error(err);

  if(isEnabled) {
    console.log('Autostart is enabled');
  }
  else {
    console.log('Autostart is not enabled');
  }

})

If you wish, you can also use Promises instead of Callbacks:

autostart.enableAutostart(key, command, path).then(() => {
  // Success!
}).catch((err) => {
  console.error(err);
  // Something bad happened
});

autostart.disableAutostart(key).then(() => {
  // Success!
}).catch((err) => {
  console.error(err);
  // Something bad happened
});

autostart.isAutostartEnabled(key).then((isEnabled) => {
  console.log('Autostart is ' + isEnabled ? 'enabled' : 'not enabled');
  // Success!
}).catch((err) => {
  console.error(err);
  // Something bad happened
});

Variables

key: Unique identifier for startup items (always required! (Make it unique))

command: Command to be executed in the specified path

path: Place in which the command will be executed (Use process.cwd() if you just want it to happen in your current working directory)

Functions

.enableAutostart Requires key, command and path, returns err.

.disableAutostart Requires key, returns err.

.isAutostartEnabled Requires key, returns err and isEnabled.

License

The MIT License (MIT)

Copyright (c) 2015 Max Rittmüller

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3.0.3

7 years ago

3.0.2

8 years ago

3.0.1

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago