Solved

JavaScript/NodeJS PluginBuilder...Future of JavaScript in FME

  • 17 August 2017
  • 6 replies
  • 13 views

Badge

I have looking at your pluginbuilder api, and have also played a little with your JavascriptCaller transformer. I am wondering if there is any intention of developing a pluginbuilder api for NodeJS? I think this is really interesting as there are so many developers out there as well as libraries that are available in NodeJS and seems like a nice fit for FME.

Also, from my own perspective, I am working on some D3 visualizations that I would like to incorporate as a transformer in FME. This would involve using some outside libraries that would be required in the transformer as well.

I can already see that for example /node_modules is in the module path and was able as a test to drop lodash in there and require it inside the JavaScriptCaller. Not sure if this is your recommended approach?

Anyway, there is not a lot of discussion right now about using javascript and NodeJS in the knowledgebase, maybe someone could share whether there is a future here or not.

Thanks, Tom

icon

Best answer by geosander 17 August 2017, 17:17

View original

6 replies

Userlevel 4
Badge +30
This is very interesting theme :)

 

 

Badge

I believe that Safe has big plans with the JavaScriptCaller in NodeJS mode, because before 2016, the JSCaller wasn't particularly useful. Not sure though if and how they prioritise these plans...

The NodeJS mode is still very beta, but has huge potential indeed. There already is an API for it and you can find the documentation in your FME program folder under fmeobjects\\nodejs\\apidoc\\index.html. However, at the moment it's far less powerful than the Python API. You can only read and write feature attributes, but you can't read any geometries, for instance.

Badge

@sander_s, thanks for sharing that. I hadn't tried working with geometry yet using JavaScript, but did do a proof of concept manipulating tabular LRS data with the JavaScriptCaller which worked out ok.

I had looked at the documentation under fmeobjects\\nodejs\\apidoc\\index.html, but it was quite sparse. The object model is very consistent with the Python model so I generally look at that.

I hope the folks from Safe weigh in here too when they get a chance. While I understand custom programming transformers isn't necessarily their first port of call, we have some unique business cases for data manipulation that will require it, and I'd love to do it using JavaScript.

Badge +2

Hi @t2

 

 

I have played with the node option with the JavaScript caller a little bit.

 

I found that to use external libraries I had to install npm independently and install the packages, then reference their full paths in the JS code inside the transformer to use them.

I am not too sure about the future of it internally, but if you have any thoughts/ideas I would definitely add them to our ideas exchange!

Badge

@jlutherthomas,

Hi.  I didn't have to hardcode the require path, because I inspected the module object to see what default paths they set up.  To do this, you can do something as simple as this in the JavaScriptCaller:

console.log(module.children)

From this you can observe the node_modules that are added.  On a windows machine for example, the path: 'c:\node_modules' is in the require search path, and creating that directory and adding a library there allows you to require it without hardcoding 'c:\node_modules\lodash' or whatever.  

Whether this is the correct approach from FME's perspective is unknown, since they didn't publish any documentation on this.  Certainly wouldn't want to put libraries in the "Program Files" directory for sure, so they would need to either let one configure the environment with the path, or standardize an approach.

Also, you don't have to (but probably should) install node independently, since they are including node with their distribution.

Anyway, that is as much as I have hacked out of this so far.

it would be great if fme could wrap npm search and npm install in a transformer! Also, did anyone get the nodejs engine working on fme server with external modules?

Reply