OpenCPU client

npm install opencpu
8 downloads in the last week
8 downloads in the last month


Build Status NPM version NGN Dependencies

node-opencpu is a OpenCPU client.


var opencpu = require("opencpu");

opencpu.rCall("/library/datasets/R/mtcars/json", {}, function (err, data) {
    if (!err) {
        console.log(data.mpg[0] + data.mpg[1]); // => 42
    } else {
        console.log("opencpu call failed.");

opencpu.rCall("/library/stats/R/rnorm/json", {
    n: 42,
    mean: 10,
    sd: 10
}, function (err, data) {
    if (!err) {
        console.log(data.length); // => 42
    } else {
        console.log("opencpu call failed.");



To install with npm:

npm install opencpu

Tested with node 0.10.23 and OpenCPU 1.2.0.

Don't forget to start the opencpu server. For instance, from R console, after installing the package opencpu. The OpenCPU server will automatically be started when the opencpu package is attached. By default, the server starts at a random port. The default port used by node-opencpu is 5307.

> library(opencpu)
Initiating OpenCPU server...
[httpuv] http://localhost:6253/ocpu
OpenCPU single-user server ready.

> opencpu$stop()
OpenCPU stopped.

> opencpu$start(5307)
[httpuv] http://localhost:5307/ocpu
npm loves you