Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including nrepl-client with all npm packages installed. Try it out:

var nreplClient = require("nrepl-client")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

nrepl-client v0.3.0

node client to interact with a Clojure nREPL server.

node.js nREPL client Build Status

Connects node.js as a nrepl client to a Clojure nrepl server.

This is different from cljs-noderepl and similar projects as it does not connect node.js as the repl "target" (so that a nrepl Clojure client can eval code in a JS context) but the other way around ;)


To connect to a running nREPL server and send and receive an eval request do:

var client = require('nrepl-client').connect({port: 7889});

client.once('connect', function() {
    var expr = '(+ 3 4)';
    client.eval(expr, function(err, result) {
        console.log('%s => ', expr, err || result);

For a more detailed example and to use node.js also to start an nREPL Clojure process see examples/simple-connect.js.

## API

### `nrepl-client`

* `connect(options)`
  * Creates a [`net.Socket`](
    connection to an nREPL server. The connection object itself will have added
    methods, see below.
  * `options`: options from the [`net.connect`]( call.
  * returns a `net.Socket` clojure connection

* clojure connection
  * Wraps [nREPL messages](
  * `clone([session,] callback)
  * `close([session,] callback)
  * `describe([verbose,] callback)
  * `eval(code, [session, id, evalFunc,] callback)
  * `interrupt(session, id, callback)
  * `loadFile(fileContent, [fileName, filePath,] callback)
  * `lsSessions(callback)
  * `stdin(stdin, callback)
  * `send(msgObj, callback)` sends a custom message

### `nrepl-client/nrepl-server`

* `start(options, callback)`
  * `options` options for configuring the nREPL server. Optional. `options == {startTimeout: NUMBER, verbose: BOOL, projectPath: STRING, hostname: STRING, port: NUMBER}`. See [nrepl-server.js](src/nrepl-server.js) for defaults.
  * `callback(err, serverState)` function called when the server is started. `serverState == {proc: PROCESS, hostname: STRING, port: NUMBER, started: BOOL, exited: BOOL, timedout: BOOL}`

* `stop(serverState, callback)`
  * `serverState` serverState returned from start
  * `callback(err)` function called when the server is stopped


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free