Node Examples/en
Node action blocks make it easy to interface a Node.js interpreter, and execute functions inside of it. Node.js is an open source interpreter for JavaScript. For details on the language and libraries, visit "NodeJS Tutorial".
There are many useful interfaces for which Node implementations are readily available and creating an interface to them is a matter of minutes of work.
This document gives a few examples.
Prerequisites[Bearbeiten]
You have to download and install "node" separately - the interpreter is not part of the expecco installation procedure (see https://nodejs.org/en/download ).
If "node" is not found along your shell's path (%PATH% on windows), you have to define the location of the node executable in the "Extras" - "Settings" - "External Interpreters" dialog. Click on the "?" icon to check if it is executable (the node's version should be displayed at the bottom).
Also, unless your node packages are installed globally or in your home folder's "node_modules", you should also add the path to your desired node_modules folder there.
Checking if Node Action Block Execution Works[Bearbeiten]
Simply create a new "Node (bridged)" action, and execute it. This will fail (red-status) if any of the above was configured incorrectly. If you get green, you should be ready to run!
Example: Getting a Map from Open Street Map[Bearbeiten]
In this example, we will use a node package called "staticmaps
", which generates streetmaps give a geo location.
- First, install the node package, by entering on the command line (i.e. cmd-window or shell window):
npm install -g staticmaps
Take a look at the package's web site https://www.npmjs.com/package/staticmaps for detail information and more examples.
- Create a new "Node (bridged)" action:
- define its code by pasting in the example code from the website:
var StaticMaps = require("staticmaps"); function execute() { var options = { width: 600, height: 400 }; var map = new StaticMaps(options);
const zoom = 13; const center = [13.437524,52.4945528]; map.render(center, zoom) .then(() => map.image.save('/tmp/center.png')) .then(() => console.log('File saved!')) .catch(function(err) { console.log(err); }); }