# startup-run

> Run scripts at startup with ease.

Latest version **0.0.10** (published 2024-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install startup-run
pnpm add startup-run
yarn add startup-run
bun add startup-run
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.10 |
| Published | 2024-02-15 |
| First published | 2023-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 8 |
| Unpacked size | 49.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | vilicvane |
| Maintainers | vilicvane |

## Links

- npm: https://www.npmjs.com/package/startup-run
- Repository: https://github.com/vilic/startup-run
- Homepage: https://github.com/vilic/startup-run#readme
- Issues: https://github.com/vilic/startup-run/issues
- npm.io page: https://npm.io/package/startup-run

## Dependencies (8)

- [chalk](https://npm.io/package/chalk.md) ^5.3.0
- [tslib](https://npm.io/package/tslib.md) ^2.6.2
- [winreg](https://npm.io/package/winreg.md) 1.2.4
- [fs-extra](https://npm.io/package/fs-extra.md) ^11.1.1
- [command-join](https://npm.io/package/command-join.md) ^3.0.0
- [@types/winreg](https://npm.io/package/@types/winreg.md) ^1.2.33
- [main-function](https://npm.io/package/main-function.md) ^0.1.7
- [@types/fs-extra](https://npm.io/package/@types/fs-extra.md) ^11.0.2

## Recent versions

- 0.0.10 (latest) — 2024-02-15
- 0.0.9 — 2024-02-12
- 0.0.8 — 2023-11-07
- 0.0.7 — 2023-11-07
- 0.0.5 — 2023-10-06
- 0.0.4 — 2023-10-06
- 0.0.3 — 2023-10-06
- 0.0.2 — 2023-10-04
- 0.0.1 — 2023-10-04
- 0.0.0 — 2023-10-04

## README

[![NPM version](https://img.shields.io/npm/v/startup-run?color=%23cb3837&style=flat-square)](https://www.npmjs.com/package/startup-run)
[![Repository package.json version](https://img.shields.io/github/package-json/v/vilic/startup-run?color=%230969da&label=repo&style=flat-square)](./package.json)
[![MIT License](https://img.shields.io/badge/license-MIT-999999?style=flat-square)](./LICENSE)

# startup-run

Run **command-line scripts** at startup with ease.

Supports **Windows**, **macOS** and **Linux** (Desktop).

## Features

- Run non-GUI scripts at startup, **hidden**.
- Run as **current user** on Windows (running as service would cause problems for scripts with UI interactions).
- Log to file.
- Auto restart (respawn) on exit.

## Installation

```bash
npm install startup-run
```

## Usage

```js
import {StartupRun} from 'startup-run';

const run = StartupRun.create('awesome-script');

await run.enable();

await run.disable();

await run.isEnabled(); // boolean

await run.start(); // start daemon.

await run.stop(); // stop daemon.

// Setup to enable/disable startup, this exits current process if either
// `enable` or `disable` is true.
await run.setup({
  enable: process.argv.includes('--startup'),
  disable: process.argv.includes('--disable-startup'),
});

StartupRun.daemonSpawned; // boolean, is current process spawned by daemon.
```

### Default Options

```js
const run = StartupRun.create('<name>', {
  command: process.execPath,
  args: process.argv.slice(1),
  cwd: process.cwd(),
  env: {},
  log: true,
  respawn: true,
});
```

## Implementations

### Windows

On Windows, it adds a startup item to registry at `HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run`, thus starting the script at login as current user.

> Solutions like `pm2` run scripts as service, which would cause problems for scripts with UI interactions.

Tested on:

- Windows 11

### macOS

On macOS, it adds a `.plist` file to `~/Library/LaunchAgents`.

Tested on:

- macOS Sonoma 14

### Linux

On Linux, it adds a `.desktop` file to `~/.config/autostart`.

Tested on:

- Ubuntu 22.04 (Desktop)

## Third Parties

### node-auto-launch

Package **startup-run** is inspired by [node-auto-launch](https://github.com/Teamwork/node-auto-launch) but for different scenarios. While `node-auto-launch` focuses on GUI applications, **startup-run** focuses on scripts instead.

It refers some implementation details from `node-auto-launch`, but is overall refactored or rewritten to better serve its own design goals.

## License

MIT License.

---
_Source: https://npm.io/package/startup-run · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
