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 which make requests to the server.
Install the module globally with:
npm install -g listen-spawn
# Navigate to your working directorycd my_project# Set up listen-spawn to run `npm test`listen-spawn -- npm test # Listening at [...]# In a separate process, curl the server to run `npm test` againcurl http://localhost:7060/ # > email@example.com test [...]
// Add the following to your "Key Bindings - User" inside the "keys": "alt+x" "command": "request" "args": "open_args": ""
The following shortcut invokes a
curl request to
alt+x is pressed. The downside is this opens a panel every time it is executed.
// Add the following to your "Key Bindings - User" inside the "keys": "alt+x" "command": "exec" "args": "cmd": "curl" ""
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.
listen-spawn installs a CLI endpoint via
npm. It is good practice to always use
-- to separate
command as this can lead to unintended parsing.
$ listen-spawnUsage: listen-spawn [options] -- command [args...]Starts server and invokes command with arguments whenever touched.Options:--port Port to start server on [default: 7060]
If you are trying to run command prompt specific commands (e.g.
echo), you will run into trouble. Unfortunately,
child_process.spawn does not like to run these. To remedy this, you will need to run it via
E:\listen-spawn> REM This will failE:\listen-spawn> listen-spawn -- echo 124 Jul 01:30:41 - [listen-spawn] Listening at...Error: spawn ENOENTE:\listen-spawn> REM To make it run, use `cmd /c`E:\listen-spawn> listen-spawn -- cmd /c echo 124 Jul 01:31:37 - [listen-spawn] Listening at24 Jul 01:31:37 - [listen-spawn] Starting new process -- cmd /c echo 1124 Jul 01:31:37 - [listen-spawn] App exited cleanly
$ listen-spawn -- mocha test/assert.js20 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 complete20 Jun 04:17:58 - [listen-spawn] App exited cleanly
$ listen-spawn -- node example/launch.js20 Jun 04:20:25 - [listen-spawn] Listening at http://localhost:7060/20 Jun 04:20:25 - [listen-spawn] Starting new process -- node example/launch.jsStarting browser[...]
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 and test via
Copyright (c) 2013 Todd Wolfson
Licensed under the MIT license.