#268 Node.js Toolkit Port

Shawn Jacobson Fri 20 Mar 2015

Lynxspring has released a Node.js port of the Open Source Haystack Java Toolkit. It is available via Bitbucket.

Brian Frank Mon 23 Mar 2015

Hi Shawn, that is really awesome! Thanks for making that available to the community. I will add a link to that project from the Downloads page. Do you want me to use the Bitbucket link you have as the main landing page?

Shawn Jacobson Tue 24 Mar 2015

Yes and thank you.

Tucker Watson Tue 24 Mar 2015

Thanks Shawn, this looks great! Is this being released under AFL 3.0?

Shawn Jacobson Tue 24 Mar 2015

That was the intention. I have updated all source files to include the license and proper attribution to the Java Haystack Toolkit. I have also removed the app.js and demo.js files from the core which removes the projects dependency on express and body-parser. These should be included by the extending application so that NodeHaystack is not determining which web framework should be used; this should be left up to the developer to determine. If you have already installed via npm, please run npm update nodehaystack to get the latest updates. I have also updated the README.md with a new example app (which uses express and body-parser) as well as adding known issues.

Shawn Jacobson Wed 25 Mar 2015

I have corrected all known issues and added a second example to the README. One is for using Express, the other for the standard Node.js HTTP server. Please add any issues to the BitBucket issue log if you come across any. Thank you!

Shawn Jacobson Fri 3 Apr 2015

Thanks for adding to the Downloads section!

Jonathan Dumaine Mon 6 Apr 2015

This is fantastic, Shawn. I just npm i'd it, going to implement it now. I'll let you know or submit a PR if I come across any bugs. :)

Shawn Jacobson Mon 27 Apr 2015

Thanks to everyone that has supplied feedback! After implementing in a real project, I am confident this is ready for a real release. As such, I have just pushed version 1.0.0 to BitBucket and NPM. Please report any feature requests or issues at BitBucket. Thanks again!!!

Sushil Sharma Sat 12 Dec 2015

Hello All, I am new to Node.js and was tring to integrate nodehaystack with angularjs i.e. calling nodehaystack api in angularjs. Can anyone help how we can achieve this??? Thank you very much... Sushil

Alex J Afflick Sun 13 Dec 2015

Hi Sushil,

You have two options to tackle this:

  1. Convert the existing NodeJS Haystack implementation to an AngularJS module by hand or using something like Browserify. This requires a bit of work upfront but would allow you to use the Javascript objects natively inside AngularJS.
  2. Create a small AngularJS client library to just parse the results of the REST calls against the server and deal with the raw strings. This is considerably easier however doesn't give you the ability to use the Haystack objects or associated functions inside the browser app.

If there are more people within the community wanting an AngularJS module, we should look at doing #1 properly. In the mean time I'd suggest going with #2.

Peter Grainger Mon 11 Jan 2016

Hi All.

Thanks to Lynxspring for open sourcing the toolkit, this will hopefully save me a lot of time. I'm hoping someone that has used the toolkit to integrate with skyspark is able to help me!

I've been attempting to use the toolkit to communicate with a SkySpark application I've installed locally using nodejs. I am able to create a HClient with the code:

// Get Haystack Client { var skySpark = new hs.HClient(http://localhost:999/api/demo/, ben, ); }

This works but when I try to open the connection using: {

skySpark.open(function(response)

console.log(response);
console.log('responded');

); }

the ASYNC callback is never called. I tracked it to the http.get in this function: { HClient.prototype.authenticate = function(callback)

var self = this;

// make request to about to get headers
var url = self.uri + "about";

http.get(url, function(res) {
  var folioAuthUri = res.headers["folio-auth-api-uri"];
  if (typeof(folioAuthUri) !== 'undefined' && folioAuthUri !== null) {
    self.authenticateFolio(self, res, callback);
    return;
  }
  console.log(res);
  var respCode = res.statusCode;
  switch (respCode) {
    case 200:
      callback(null, self);
      return;
    case 302:
    case 401:
      self.authenticateBasic(self, res, callback);
      return;
    default:
      callback(new Error("Unexpected Response Code: " + respCode));
      return;
  }
}).on('error', function(e) {
  callback(e);
});

};

I'm assuming there is a problem with the http.get as the same happens if I run the following. {

http.get(http://localhost:999/api/demo/, function(response)

console.log(response);

); }

Peter Grainger Tue 12 Jan 2016

Hi All.

Fixed my own issue :S

This was an issue with using localhost:999 instead of the standard localhost (with port 80).

For some reason the http.get didn't work with a port.

Hope this helps someone else. If anyone needs it I've written an nodejs app that writes data to skyspark history

// Module dependencies .
var hs = require('nodehaystack'),
  http = require('http'),
  url = require('url'),
  moment = require('moment-timezone');

// Get Haystack Client
var skySpark = new hs.HClient('http://localhost/api/demo/', 'ben', '');

// Open the connection to SkySpark
skySpark.open(function(response){
  // Set the DischarePressure to 10 at 12th Jan 16 12:15. 
  var id = new hs.HRef('Carytown.RTU-1.DischargePressure', '');
  var data = new hs.HHisItem(new hs.HDateTime(new hs.HDate(2016, 01, 12), 
                                                                              new hs.HTime(12, 15, 00, 00), 
                                                                              new hs.HTimeZone('New_York', moment().tz('America/New_York')),
                                                                                0),
                                              new hs.HNum(10, 'inHâ‚‚O'));

  // Write the data to the history.
  skySpark.hisWrite(id, new Array(data), function(response) {
      console.log(response);
  });
});

Imen Benida Thu 31 Mar 2016

Hi , Thanks for sharing this example, How can i return a hisGrid from skyspark in order to display a chart with node.js ?

Kevin Kelley Tue 8 Nov 2016

First of all, @Shawn, thanks for this port, it's very useful to us.

I need to report a bug -- a simple one-line fix to the HZincReader class, in the _readGrids method -- reading multiple grids returns an empty list.

The problem is in line 727 of the io/HZincReader.js file;

if (notdone(this.cur, false)) {

should be changed to this:

if (notdone(self.cur, false)) {

readGrids is a prototype method, with a this; but the _readGrids helper func is a plain function that gets this passed in as the first parameter, self.

I'd like to get that put into the upstream, so that npm update will stop overwriting my local change...

Again thanks.

Mitchell Fontaine Tue 9 Apr

Hello, Is this haystack client still supported? I am trying to connect to my Skyspark instance, but it is not working.

My code is

const haystack = require('nodehaystack')
const http = require('https')
const request = require('request')
const url = require('url')
const moment = require('moment-timezone')

var skyspark = new haystack.HClient('https://myDNS/api/projName','user','pass')

skyspark.open((response) => {
    console.log(response);
    skyspark.evaluate('read(equip)', (returned) => {
       console.log(returned);
    })
})

And what is getting logged to the console is

{ Error: write EPROTO 9040:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:openssl\ssl\record\ssl3_record.c:252:

at WriteWrap.afterWrite [as oncomplete] (net.js:782:14) errno: 'EPROTO', code: 'EPROTO', syscall: 'write' }

Thanks

Login or Signup to reply.