A Read-Eval-Print-Loop (REPL) is an interactive environment that accepts user input, evaluates it, and outputs the result back to the user.
It is possible to connect to a live, running application by using the replify
(https://www.npmjs.org/package/replify) and repl-client
(https://www.npmjs.org/package/repl-client) modules. The first one will add a REPL to our application, while the second one can be used to connect to it. The following are the commands to use replify
and repl-client
:
$ npm i replify $ npm i repl-client –g
First, we should set up a quick sample application using the following code:
var replify = require('replify'); var express = require('express'); var app = express(); app.use(function(req, res, next) { res.send('all good'); }); app.listen(process.env.PORT || 7777); replify('replify-app-' + process.pid, app); console.log('Use the command below to connect to the REPL:'); console.log('rc /tmp/repl/replify-app-' + process.pid + '...