Node module: npm install --save octo-client

For the past three days, I've been creating and publishing an npm module for Node JS for OctoPrint. This should make it easy to create Node-based interfaces for OctoPrint to exercise the REST API. It is expected that you'd run this on a computer other than the OctoPrint server itself. I suppose you could run it on the server, too.

npm package
github

Assumptions

  • You have node and npm installed
mkdir ~/sites/myApp && cd ~/sites/myApp
npm init                                # go with the defaults
npm install --save octo-client
nano index.js

index.js:

var OctoPrint = require('octo-client');

OctoPrint.printerState(function(ptr){
  if (ptr.state.flags.operational) {
    var targetHotend1 = ptr.temperature.tool0.target;
    console.log('-> The first hotend is currently ' + targetHotend1 + 'C degrees.');
  }
});

Then run it:

node .

-> The first hotend is currently 24C degrees.

Of course, this behaves like a command line interface (CLI) for this example. You could be clever and wrap all of this in a shell script like /usr/local/bin/get-ptr-temp or similar and then just run get-ptr-temp.

The overall intention for this is to write Node applications either for a local website or a phone app, perhaps. The interface requires network connectivity to your printer and assumes port 80.

Version 1.1.3 of this Node module now allows you to use a port other than the default port 80.

Looks like it's been downloaded about 250 times now. :slight_smile: