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:
Development Experience: Full IDE support with TypeScript, debugging capabilities, and Deno's built-in development tools
Security: Keep sensitive code on your infrastructure when compliance or security policies require it
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.
2. Create your Analysis
2-1. Create a new file for your Analysis. For this example, we'll call it analysis.ts:
import { Analysis, Device, Utils } from "jsr:@tago-io/sdk";
import { DateTime } from "npm:luxon";
async function myAnalysis(context: any) {
// Your analysis logic here
console.log("Running external Deno analysis");
console.log("Context:", context);
const now = DateTime.now().toISO();
console.log("Current time:", now);
}
Analysis.use(myAnalysis, { token: "MY-ANALYSIS-TOKEN-HERE" });
Deno runs with secure defaults. Create a deno.json configuration file to specify permissions:
{
"tasks": {
"start": "deno run --allow-net --allow-env analysis.ts"
}
}
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:
Access your Analysis page at TagoIO
Select External for 'Run the scripts from'
Copy the generated token
For better security, use environment variables:
const token = Deno.env.get("ANALYSIS_TOKEN") || "MY-ANALYSIS-TOKEN-HERE";
Analysis.use(myAnalysis, { token });
Run your Analysis:
# Using the task defined in deno.json
deno task start
# Or directly
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 ...