# listen-spawn

> Start a HTTP server which runs commands when pinged.

Latest version **0.7.3** (published 2013-08-05) · 0 weekly downloads

## Install

```sh
npm install listen-spawn
pnpm add listen-spawn
yarn add listen-spawn
bun add listen-spawn
```

Provides the command `listen-spawn`.

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.3 |
| Published | 2013-08-05 |
| First published | 2013-06-20 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.6.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Todd Wolfson |
| Maintainers | twolfson |
| Keywords | server, listen, spawn, command, http, run, exec, ping |

## Links

- npm: https://www.npmjs.com/package/listen-spawn
- Repository: https://github.com/twolfson/listen-spawn
- Issues: https://github.com/twolfson/listen-spawn/issues
- npm.io page: https://npm.io/package/listen-spawn

## Dependencies (3)

- [optimist](https://npm.io/package/optimist.md) ~0.5.2
- [fn-colors](https://npm.io/package/fn-colors.md) ~0.1.0
- [single-child](https://npm.io/package/single-child.md) ~0.3.3

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.7.3 (latest) — 2013-08-05
- 0.7.2 — 2013-07-29
- 0.7.1 — 2013-07-24
- 0.7.0 — 2013-07-24
- 0.6.1 — 2013-07-05
- 0.6.0 — 2013-06-28
- 0.5.0 — 2013-06-27
- 0.4.1 — 2013-06-22
- 0.4.0 — 2013-06-22
- 0.3.0 — 2013-06-22
- 0.2.2 — 2013-06-22
- 0.2.1 — 2013-06-22
- 0.2.0 — 2013-06-22
- 0.1.1 — 2013-06-22
- 0.1.0 — 2013-06-20

## README

# listen-spawn [![Build status](https://travis-ci.org/twolfson/listen-spawn.png?branch=master)](https://travis-ci.org/twolfson/listen-spawn)

Start a HTTP server which runs commands when pinged.

This is **intended for development use only**. It is supported and tested on Linux and Windows.

It was designed to allow for execution of semi-frequent commands (e.g. a blocking command, starting a browser). This is complimented by [text editor specific plugins][plugins] which make requests to the server.

Below is a screenshot of using [Sublime Text 2][subl] with [sublime-request][request] and a keyboard shortcut to launch [browser-launcher][launcher] tests.

![Sublime Text 2 using sublime-request and browser-launcher][screenshot]

[plugins]: #sublime-text-plugin
[subl]: http://sublimetext.com/
[screenshot]: screenshot.png
[launcher]: https://github.com/substack/browser-launcher

## Getting Started
Install the module globally with: `npm install -g listen-spawn`

```sh
# Navigate to your working directory
cd my_project

# Set up listen-spawn to run `npm test`
listen-spawn -- npm test # Listening at http://localhost:7060/ [...]

# In a separate process, curl the server to run `npm test` again
curl http://localhost:7060/ # > my_project@0.1.0 test [...]
```

### Integrating with Sublime Text 2
#### sublime-request
[sublime-request][request] is a [Sublime Text 2][subl] plugin which adds the command `request`. The following shortcut makes a `curl` request to `http://localhost:7060/`.

```js
// Add the following to your "Key Bindings - User" inside the []
{ "keys": ["alt+x"], "command": "request", "args": {"open_args": ["http://localhost:7060/"]} }
```

[request]: https://github.com/twolfson/sublime-request

#### Out of the box solution
The following shortcut invokes a `curl` request to `http://localhost:7060/` when `alt+x` is pressed. The downside is this opens a panel every time it is executed.

```js
// Add the following to your "Key Bindings - User" inside the []
{ "keys": ["alt+x"], "command": "exec", "args": {"cmd": ["curl", "http://localhost:7060/"]} }
```

### File watching based solution
If you are looking for a solution which performs an action when a file changes rather than when a server is pinged, then you should checkout [nodemon][].

[nodemon]: https://github.com/remy/nodemon

## Documentation
`listen-spawn` installs a CLI endpoint via `npm`. It is good practice to always use `--` to separate `options` from `command` as this can lead to unintended parsing.

```sh
$ listen-spawn
Usage: listen-spawn [options] -- command [args...]
Starts server and invokes command with arguments whenever touched.

Options:
  --port  Port to start server on  [default: 7060]
```

### Windows caveats
If you are trying to run command prompt specific commands (e.g. `echo`), you will run into trouble. Unfortunately, [`child_process.spawn`][cp-spawn] does not like to run these. To remedy this, you will need to run it via `cmd /c`.

```bat
E:\listen-spawn> REM This will fail
E:\listen-spawn> listen-spawn -- echo 1
24 Jul 01:30:41 - [listen-spawn] Listening at http://localhost:7060/
...
Error: spawn ENOENT
E:\listen-spawn> REM To make it run, use `cmd /c`
E:\listen-spawn> listen-spawn -- cmd /c echo 1
24 Jul 01:31:37 - [listen-spawn] Listening at http://localhost:7060/
24 Jul 01:31:37 - [listen-spawn] Starting new process -- cmd /c echo 1
1
24 Jul 01:31:37 - [listen-spawn] App exited cleanly
```

[cp-spawn]: http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

## Examples
### Run a specific test
```sh
$ listen-spawn -- mocha test/assert.js
20 Jun 04:17:58 - [listen-spawn] Listening at http://localhost:7060/
20 Jun 04:17:58 - [listen-spawn] Starting new process -- mocha test/assert.js

  ․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․

  42 tests complete (16 ms)

20 Jun 04:17:58 - [listen-spawn] App exited cleanly
```

### Script testing a browser launcher
```sh
$ listen-spawn -- node example/launch.js
20 Jun 04:20:25 - [listen-spawn] Listening at http://localhost:7060/
20 Jun 04:20:25 - [listen-spawn] Starting new process -- node example/launch.js
Starting browser
[...]
```

## Donating
Support this project and [others by twolfson][gittip] via [gittip][].

[![Support via Gittip][gittip-badge]][gittip]

[gittip-badge]: https://rawgithub.com/twolfson/gittip-badge/master/dist/gittip.png
[gittip]: https://www.gittip.com/twolfson/

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via [grunt](https://github.com/gruntjs/grunt) and test via `npm test`.

## License
Copyright (c) 2013 Todd Wolfson

Licensed under the MIT license.

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