Running Analysis as External using Node.JS

Running Analysis as External using Node.JS

Analysis is what allows you to create powerful applications on TagoIO.  When creating analysis you have to choose between running it at TagoIO or External, which means that you will run on your machine.

You can choose to run the analysis on an external machine for a few reasons:

  1. Development Progress: While developing an analysis is best to have a full IDE and debugging mode, which is only available with Node.js on your machine.
  2.  Security: Could be the case of your company having legal issues with the code, and you can't or don't want to upload the code to TagoIO services.
  3.  Using Third Packages:  The analysis has in-build third packages in the environment, like axios and moment.js, but you may want to use others. In combination with the Analysis-Builder, you can use any third package you like and build an even more powerful script for TagoIO.

So, let's start with the instructions you need to get your analysis working in an external environment.


1. Install Node.js and NPM

Node.js is a powerful and relatively new programing language developed using JavaScript. It is a non-blocking and event-driven language that has been adopted for several developers and companies to deal with data-intensive real-time applications. Learn more about node.js.

Open Node.js Installation Guide for instructions on how to install NPM and Node.js.


2. Create your Environment

In order to start writing your code, you first must setup the environment with Node.JS and NPM.

2-1. Open your favorite command-line tool like the Windows Command Prompt, PowerShell, Cygwin, Bash or the Git shell (which is installed along with Github for Windows).  Then create or navigate to your new project folder.

2-2. If the folder is empty, you must write in the command-line npm init and fill all prompted requests. If this is your first time, you can leave all default by just pressing enter.

2-3. Now you must install Tago sdk and TagoIO-Builder SDK. Enter in your command-line npm install --save @tago-io/sdk and npm install -g @tago-io/builder  This will start the installation of the TagoIO SDK and the TagoIO-Builder if you wish to upload your script later at TagoIO.

To know how to use the SDK for coding an Analysis, use our SDK documentation.

 2-4. Now you can create your analysis archive. For this instruction, let's call it analysis.js. Open it with your favorite editor, like Visual Studio Code or even Notepad, You can write the code exactly as you would do on TagoIO editor. 

You can get the Hello World analysis example by clicking here.

3. Running your Analysis

After the code and the environment set, you only need to make sure you put the right Analysis token into your analysis file.

In order to do that, every analysis has the following line below. You must replace  MY-ANALYSIS-TOKEN-HERE by your analysis token.

module.exports = new Analysis(myAnalysis, { token: 'MY-ANALYSIS-TOKEN-HERE' } );

You can get the analysis token by accessing your analysis page at TagoIO and selecting  External for 'Run the scripts from'. Create a new analysis if you don't have any.


Now all you have to do is write at your command-line tool node ./analysis.jsYou should see the following prompt at your command-line tool:

Go back to Tago and click "Save and Run" or just "Run" to run your script. You can also configure an action to run your script automatically. 

4. Use Analysis-Builder to Upload the Script

If you only want to run the scripts on your machine, this step is not required. But if you want to build powerful scripts to upload at TagoIO, with several folders, imports, and third-party packages, you must use the analysis-builder to compile the scripts.

To do that is simple, just enter your command line tool and follow these instructions:

  1. The @tago-io/builder must be installed globally by npm install -g @tago-io/builder 
  2. Type in your terminal analysis-builder my_script.js
  3. Upload the generated new_name.tago-io.js file to your analysis at TagoIO.

More Examples

You can check our analysis examples with the full environment already set up for you below:

Now you have everything you need to know about running analysis in your machine and can start to creating full applications and powerful analysis using TagoIO


    • Related Articles

    • Creating Analysis

      Creating your own analysis is easy. First, click on Analysis on the sidebar, then click the + Add Analysis button in the upper right of the analysis main screen. Just write a name and you’re ready to go! 1. Name What you usually use to identify your ...
    • Analysis Overview

      Analysis is a powerful feature that experts and developers can use to implement scripts to analyze and manipulate data from any device in real-time. The scripts that run at TagoIO are programmed with the Node.js TagoIO's SDK. Get more instructions on ...
    • Node.js SDK

      You can access our SDK documentation on: https://js.sdk.tago.io If you are looking for documentation for old version (9.x.x) you access it on: https://tago-sdk-js-documentation.rtfd.io/ The old SDK will be discontinued at 2030. When executing ...
    • Running Analysis via Action

      Actions have the power to initiate scripts that run in the Analysis. This is a very powerful feature, as you can define exactly when your code will run. For example, you can run an Analysis every time data is sent from a device, or when it meets a ...
    • Analysis Service

      Every time the Analysis runs one script, its runtime duration is counted against the limit in that specific Profile (increment of 1 second). This limit defines the total available runtime your Analyses can have to run inside TagoIO. For example: if ...