# @carnesen/bitcoin-service

> A Node.js library for managing the bitcoin service `bitcoind`

Latest version **0.0.1** (published 2019-02-17) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @carnesen/bitcoin-service
pnpm add @carnesen/bitcoin-service
yarn add @carnesen/bitcoin-service
bun add @carnesen/bitcoin-service
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2019-02-17 |
| First published | 2019-02-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 3 |
| Unpacked size | 31.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Chris Arnesen |
| Maintainers | carnesen |

## Links

- npm: https://www.npmjs.com/package/@carnesen/bitcoin-service
- Repository: https://github.com/carnesen/bitcoin-service
- Homepage: https://github.com/carnesen/bitcoin-service#readme
- Issues: https://github.com/carnesen/bitcoin-service/issues
- npm.io page: https://npm.io/package/@carnesen/bitcoin-service

## Dependencies (3)

- [signal-exit](https://npm.io/package/signal-exit.md) 3.0.2
- [@types/signal-exit](https://npm.io/package/@types/signal-exit.md) 3.0.0
- [@carnesen/bitcoin-config](https://npm.io/package/@carnesen/bitcoin-config.md) 0.0.3

## Recent versions

- 0.0.1 (latest) — 2019-02-17
- 0.0.0 — 2019-02-11
- 0.0.0-0 — 2019-02-07

## README

# @carnesen/bitcoin-service [![npm version](https://badge.fury.io/js/%40carnesen%2Fbitcoin-service.svg)](https://badge.fury.io/js/%40carnesen%2Fbitcoin-service) [![Build Status](https://travis-ci.com/carnesen/bitcoin-service.svg?branch=master)](https://travis-ci.com/carnesen/bitcoin-service)

A Node.js library for managing the bitcoin service `bitcoind`. The package includes runtime JavaScript files suitable for Node.js >=8 as well as the corresponding TypeScript type declarations.

## Usage

Here is a little TypeScript Node.js script that starts `bitcoind`:
```ts
// example.ts
import { startService } from '@carnesen/bitcoin-service';
const bitcoinHome = '/usr/local/bitcoin-0.17.1';
(async () => {
  try {
    await startService({ bitcoinHome });
    process.exit(0);
  } catch (ex) {
    console.log(ex);
    process.exit(1);
  }
})()
```

Running the script looks like:
```
$ ts-node example.ts
Bitcoin server starting
```

## API
### `startService(configFilePath, bitcoinHome?): Promise<{changed}>`
Sets `daemon` to `true` in the configuration file and starts `bitcoind` if it's not running already

#### `configFilePath`
`string`. Absolute path of a bitcoin configuration file. Will be created if it does not already exist.

#### `bitcoinHome`
Optional `string`. Absolute path of a directory where the bitcoin server software is installed. If not provided, `` `${bitcoinHome}/bin` `` must be on your `PATH`.

#### `changed`
`boolean`. Is `false` if `bitcoind` was already running, `true` if the service was successfully started.

### `stopService(configFilePath): Promise<{changed}>`
Stops `bitcoind` if it's running

#### `changed`
`boolean`. Is `false` if `bitcoind` wasn't running. Is `true` if the service was running and successfully stopped.

### `restartService(configFilePath, bitcoinHome?): Promise<{changed}>`
Stops and starts `bitcoind` as documented above.

### `isServiceRunning(configFilePath): Promise<boolean>`
The returned promise resolves to `true` if the service is running or `false` if it is not.

## More information
Check out [the tests directory](src/__tests__) for more examples of how it works. If you encounter any bugs or have any questions or feature requests, please don't hesitate to file an issue or submit a pull request on this project's repository on GitHub.

## Related
- [@carnesen/bitcoin-service-cli](https://github.com/carnesen/bitcoin-service-cli): A Node.js CLI and library for managing the bitcoin server process `bitcoind`

- [@carnesen/bitcoin-config](https://github.com/carnesen/bitcoin-config): A Node.js library for bitcoin server software configuration

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