# ngrok-daemon

> Very basic Node.js ngrok wrapper

Latest version **0.5.0** (published 2015-06-23) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install ngrok-daemon
pnpm add ngrok-daemon
yarn add ngrok-daemon
bun add ngrok-daemon
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2015-06-23 |
| First published | 2015-06-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Sasha |
| Maintainers | kossnocorp |

## Links

- npm: https://www.npmjs.com/package/ngrok-daemon
- Repository: https://github.com/kossnocorp/ngrok-daemon
- Issues: https://github.com/kossnocorp/ngrok-daemon/issues
- npm.io page: https://npm.io/package/ngrok-daemon

## Dependencies (2)

- [tail](https://npm.io/package/tail.md) ^0.4.0
- [temp](https://npm.io/package/temp.md) ^0.8.3

## Recent versions

- 0.5.0 (latest) — 2015-06-23
- 0.4.0 — 2015-06-23
- 0.3.1 — 2015-06-23
- 0.3.0 — 2015-06-23
- 0.2.0 — 2015-06-20
- 0.1.0 — 2015-06-19

## README

# ngrok-daemon [![Build Status](https://travis-ci.org/kossnocorp/ngrok-daemon.svg?branch=master)](https://travis-ci.org/kossnocorp/ngrok-daemon) [![npm version](https://badge.fury.io/js/ngrok-daemon.svg)](http://badge.fury.io/js/ngrok-daemon)

Very basic Node.js [ngrok](https://ngrok.com) wrapper. Unline [ngrok](https://www.npmjs.com/package/ngrok)
npm package, ngrok-daemon do not use `child_process` so:

1. ngrok tunnel won't be killed automatically,
2. logs are streamed to file,
3. you have the ngrok PID.

It's really basic so you will get only `start`, `stop` and `isRunning` functions.

## Installation

To install ngrok-daemon you need to run `npm install`:

```
npm install ngrok-daemon --save
```

ngrok-daemons uses native `Promise` object,
so it [won't run on outdated Node.js](http://stackoverflow.com/questions/21564993/native-support-for-promises-in-node-js).

## API

API is small and simple. Every function returns [`Promise`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise).
When ngrok-daemon fails to perform some action, it rejects the promise.

### `start`

Start ngrok on given port and get `tunnel` object:

``` js
var ngrok = require('ngrok-daemon')

ngrok.start(4000) // Port
  .then(function(tunnel) {
    // Tunnel has three propeties:
    // - url - URL to the started tunnel
    // - pid - process id of ngrok (PID)
    // - log - path to ngrok log in temporary directory
  })
  .catch(function() {
    // Failed to start ngrok on given port (eg ngrok is not installed)
  })
```

**Important**: Node.js process won't exit automatically after spawning
background process, so if you need to stop it, call `process.exit` once
you got a tunnel data.

It's possible to specify custom shell script that will start ngrok.
To do it, pass source string as an option:

``` js
ngrok.start('ngrok -log=stdout 4000')
```

### `stop`

Stop ngrok process using the PID:

``` js
ngrok.stop(tunnel.pid)
```

It's possible to specify custom shell script that will stop ngrok.
To do it, pass source string as the first argument:

``` js
ngrok.stop('kill ' + tunnel.pid)
```

### `isRunning`

Resolves promise if it is running and rejects if isn't:

``` js
ngrok.isRunning(tunnel.pid)
  .then(function() {
    // ngrok is running
  })
  .catch(function() {
    // Nope
  })
```

It's possible to specify custom shell script that will check if ngrok
is running. To do it, pass source string as the first argument:

``` js
ngrok.isRunning('kill -0 ' + tunnel.pid)
```

**Important**: empty stdout will be treated as "not running" and vice versa.

## Tests

To run the tests you need:

1. Internet connection,
2. free port `4999`,
3. `ngrok` binary avaliable in `$PATH`,

To start the tests in "watch" (autotests) mode:

```
npm test
```

**Warning**: `killall ngrok` will be invoked after each `it` statement,
so don't be surprised when your own ngrok tunnel will be killed.

## License

ngrok-daemon is released under the [MIT License](./LICENSE.md).

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