├── .gitignore ├── History.md ├── Readme.md ├── examples ├── simple-http │ ├── package.json │ └── simple-http.js └── socket.io │ ├── client.js │ ├── io.js │ ├── mix.js │ └── package.json ├── package-lock.json ├── package.json └── repl-client.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | .DS_Store 3 | .idea 4 | nohup.out 5 | npm-debug.log 6 | logs 7 | node_modules 8 | pids 9 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 0.3.0 / 2014-03-25 3 | ================== 4 | 5 | * Added support for input over stdin. (@vvo) 6 | * Now limited to node v0.10+. 7 | 8 | 0.2.1 / 2013-04-16 9 | ================== 10 | 11 | * Correctly handle setRawMode on stdin in node v0.10. (@kitcambridge) 12 | * Simplify socket close, just exit. 13 | 14 | 0.2.0 / 2013-04-09 15 | ================== 16 | 17 | * Upgraded stdin handling for node v0.10. 18 | 19 | v0.1.1 / 2012-10-18 20 | =================== 21 | 22 | * Fixed reference to optimist on help(). 23 | 24 | 0.1.0 / 2012-10-17 25 | ================== 26 | 27 | * Release repl-client (rc) at NodeDublin. 28 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # REPL Client (rc) 2 | 3 | REPL client with tab completion and history. A simple, npm installable alternative to netcat (nc) and socat. 4 | 5 | ## Install 6 | 7 | npm install -g repl-client 8 | 9 | ## Usage 10 | 11 | $ rc /tmp/repl/socket.io.sock 12 | 13 | ## Adding a REPL to your app. 14 | 15 | To easily add a REPL to your Node.js app, use [replify](https://github.com/dshaw/replify). 16 | 17 | ## Compatibility 18 | 19 | `repl-client` only works under node 0.10. Upgrade. 20 | 21 | ## Use cases 22 | 23 | As a repl 24 | ```shell 25 | rc /tmp/repl/hello.sock 26 | hello> require('os').type() 27 | 'Linux' 28 | ``` 29 | 30 | Using `stdin` pipe 31 | ```shell 32 | echo "require('os').type()" | rc /tmp/repl/hello.sock 33 | hello> require('os').type() 34 | 'Linux' 35 | hello> % 36 | ``` 37 | 38 | ## Props 39 | 40 | - Special thanks to @TooTallNate for all the work he's done in improving node's REPL. 41 | - The starting point for this module was Nate's "full featured" REPL client: https://gist.github.com/2209310 42 | - We have been using this at @Voxer and love it. 43 | 44 | ## License 45 | 46 | (The MIT License) 47 | 48 | Copyright (c) 2012-2014 Daniel D. Shaw, http://dshaw.com 49 | 50 | Permission is hereby granted, free of charge, to any person obtaining 51 | a copy of this software and associated documentation files (the 52 | 'Software'), to deal in the Software without restriction, including 53 | without limitation the rights to use, copy, modify, merge, publish, 54 | distribute, sublicense, and/or sell copies of the Software, and to 55 | permit persons to whom the Software is furnished to do so, subject to 56 | the following conditions: 57 | 58 | The above copyright notice and this permission notice shall be 59 | included in all copies or substantial portions of the Software. 60 | 61 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 62 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 63 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 64 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 65 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 66 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 67 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 68 | -------------------------------------------------------------------------------- /examples/simple-http/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "repl-client-example-simple-http", 3 | "version": "0.3.0", 4 | "description": "Use rc with raw http.", 5 | "author": "Daniel D. Shaw (http://dshaw.com)", 6 | "license": "MIT", 7 | "main": "./simple-http.js", 8 | "scripts": { 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "dependencies": { 12 | "replify": "^1.2.0" 13 | }, 14 | "devDependencies": {}, 15 | "engines": { 16 | "node": ">= 0.10.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/simple-http/simple-http.js: -------------------------------------------------------------------------------- 1 | var replify = require('replify') 2 | , app = require('http').createServer() 3 | 4 | replify('simple-http-101', app) 5 | 6 | app.on('request', function onRequest(req, res) { 7 | res.writeHead(200, {'Content-Type': 'text/plain'}) 8 | res.end('Hello, replify!\n') 9 | }) 10 | 11 | app.listen(Number(process.argv[2]) || 8080) 12 | -------------------------------------------------------------------------------- /examples/socket.io/client.js: -------------------------------------------------------------------------------- 1 | var client = require('socket.io-client') 2 | , replify = require('replify') 3 | 4 | var cid = process.argv[2] || 'x' 5 | , socket = client.connect('http://localhost:8888') 6 | 7 | socket.on('connect', function () { 8 | console.log('client %d connected', cid) 9 | socket.emit('join', cid) 10 | }) 11 | 12 | replify('socket.io-client_'+cid, socket) 13 | -------------------------------------------------------------------------------- /examples/socket.io/io.js: -------------------------------------------------------------------------------- 1 | var replify = require('replify') 2 | , io = require('socket.io').listen(8888, function () { console.log('Socket.io listening on :8888') }) 3 | , app = io 4 | 5 | io.on('connection', function (socket) { 6 | socket.on('join', function (room) { 7 | console.log('args', arguments) 8 | console.log('Client request to join room %d', room) 9 | socket.join(room) 10 | socket.send('Welcome to room ' + room) 11 | }) 12 | }) 13 | 14 | 15 | replify('socket.io', app) 16 | -------------------------------------------------------------------------------- /examples/socket.io/mix.js: -------------------------------------------------------------------------------- 1 | var replify = require('replify') 2 | , mix = require('mixture').mix('socket.io-clients') 3 | 4 | var count = 5 5 | , clientId = 0 6 | 7 | // socket.io-client instances 8 | var client = mix.task('socket.io-client', { filename: 'client.js' }) 9 | 10 | for (var i = 0; i < count; i++) { 11 | client.fork({ args: [clientId++] }) 12 | } 13 | 14 | replify('socket.io-clients-mix', mix) -------------------------------------------------------------------------------- /examples/socket.io/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "repl-client-example-socket.io", 3 | "version": "0.1.0", 4 | "description": "Use rc with socket.io.", 5 | "author": "Daniel D. Shaw (http://dshaw.com)", 6 | "license": "MIT", 7 | "main": "./rc.io.js", 8 | "scripts": { 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "dependencies": { 12 | "mixture": "~0.1.2", 13 | "optimist": "~0.3.5", 14 | "replify": "~1.0.0", 15 | "socket.io": "~0.9.10", 16 | "socket.io-client": "~0.9.10" 17 | }, 18 | "devDependencies": {}, 19 | "engines": { 20 | "node": ">= 0.8.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "repl-client", 3 | "version": "0.3.1", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "optimist": { 8 | "version": "0.3.7", 9 | "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.3.7.tgz", 10 | "integrity": "sha1-yQlBrVnkJzMokjB00s8ufLxuwNk=", 11 | "requires": { 12 | "wordwrap": "~0.0.2" 13 | } 14 | }, 15 | "wordwrap": { 16 | "version": "0.0.3", 17 | "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", 18 | "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=" 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "repl-client", 3 | "version": "0.3.1", 4 | "description": "REPL Client (rc) with tab completion and history. A simple, npm installable alternative to netcat (nc) and socat.", 5 | "keywords": [ 6 | "repl", 7 | "replify", 8 | "observability" 9 | ], 10 | "author": "Daniel D. Shaw (http://dshaw.com)", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/dshaw/repl-client.git" 14 | }, 15 | "bugs": { 16 | "url": "http://github.com/dshaw/repl-client/issues" 17 | }, 18 | "license": "MIT", 19 | "main": "./repl-client.js", 20 | "bin": { 21 | "rc": "./repl-client.js" 22 | }, 23 | "scripts": { 24 | "test": "echo \"Error: no test specified\" && exit 1" 25 | }, 26 | "directories": { 27 | "examples": "examples" 28 | }, 29 | "dependencies": { 30 | "optimist": "^0.3.7" 31 | }, 32 | "devDependencies": {}, 33 | "engines": { 34 | "node": ">= 0.10.0" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /repl-client.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /*! 4 | * repl-client 5 | * Copyright(c) 2012-2014 Daniel D. Shaw 6 | * MIT Licensed 7 | */ 8 | 9 | /** 10 | * Module dependencies 11 | */ 12 | 13 | var net = require('net') 14 | , stream = require('stream') 15 | , optimist = require('optimist') 16 | , options = optimist.options('p', { alias : 'path' }).argv 17 | 18 | /** 19 | * Configuration 20 | */ 21 | 22 | if (!options.path) { 23 | if (!options._.length) { 24 | console.log(optimist.usage('Usage: $0 /tmp/repl/socket.io.sock').help()) 25 | process.exit(1) 26 | } else { 27 | options.path = options._[0] 28 | } 29 | } 30 | 31 | /** 32 | * REPL Client 33 | */ 34 | 35 | var socket = net.connect(options) 36 | 37 | process.stdin 38 | .pipe(socket) 39 | .pipe(process.stdout) 40 | 41 | socket.on('close', function () { 42 | if (process.stdin.setRawMode) 43 | process.stdin.setRawMode(false) 44 | process.stdin.emit('end') 45 | console.log('') 46 | process.exit() 47 | }); 48 | 49 | if (process.stdin.setRawMode) { 50 | socket.on('connect', function activateRawMode() { 51 | process.stdin.setRawMode(true) 52 | }) 53 | } 54 | --------------------------------------------------------------------------------