Running Analysis as External using Deno

Running Analysis as External using Deno

Analysis enables you to create powerful applications on TagoIO. When creating an Analysis, you can choose between running it at TagoIO or External, which means running it on your own infrastructure.

Running Analysis externally with Deno provides several advantages:
  1. Development Experience: Full IDE support with TypeScript, debugging capabilities, and Deno's built-in development tools
  2. Security: Keep sensitive code on your infrastructure when compliance or security policies require it
  3. Performance: Direct control over execution environment and resource allocation

1. Install Deno

Deno is a secure runtime for JavaScript and TypeScript built on V8, Rust, and Tokio. It includes TypeScript support out of the box, a built-in formatter and linter, and secure defaults. Learn more about Deno.

Visit the Deno Installation Guide for platform-specific instructions.

2. Create your Analysis

2-1. Create a new file for your Analysis. For this example, we'll call it analysis.ts:
  1. import { Analysis, Device, Utils } from "jsr:@tago-io/sdk";
  2. import { DateTime } from "npm:luxon";

  3. async function myAnalysis(context: any) {
  4.   // Your analysis logic here
  5.   console.log("Running external Deno analysis");
  6.   console.log("Context:", context);
  7.   
  8.   const now = DateTime.now().toISO();
  9.   console.log("Current time:", now);
  10. }

  11. Analysis.use(myAnalysis, { token: "MY-ANALYSIS-TOKEN-HERE" });


3. Configure Permissions

Deno runs with secure defaults. Create a deno.json configuration file to specify permissions:
  1. {
  2.   "tasks": {
  3.     "start": "deno run --allow-net --allow-env analysis.ts"
  4.   }
  5. }
The --allow-net flag permits network requests to TagoIO APIs, and --allow-env allows reading environment variables.

4. Running your Analysis

Replace MY-ANALYSIS-TOKEN-HERE with your actual Analysis token. You can get this by:
  1. Access your Analysis page at TagoIO
  2. Select External for 'Run the scripts from'
  3. Copy the generated token
For better security, use environment variables:
  1. const token = Deno.env.get("ANALYSIS_TOKEN") || "MY-ANALYSIS-TOKEN-HERE";

  2. Analysis.use(myAnalysis, { token });
Run your Analysis:
  1. # Using the task defined in deno.json
  2. deno task start

  3. # Or directly
  4. deno run --allow-net --allow-env analysis.ts
You should see output indicating the Analysis is connected and waiting for triggers.

More Examples


You now have everything needed to run external Analysis with Deno, leveraging TypeScript support, remote imports, and modern development tools to create powerful TagoIO applications.







    • Related Articles

    • 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 ...
    • Analysis Overview

      Analysis lets you run custom code inside TagoIO to process data in real time, call third‑party APIs, and work with your own TagoIO resources. Common things people do with Analyses: Convert units and run math on variables Write new values into other ...
    • 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 ...
    • 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 ...