Configuration and Running JsN


Running

JsN.exe <path_to_config.json>

Examples:

JsN.exe config.json
JsN.exe "C:\scripts\monitor.json"
JsN.exe TCa\CaMonitor.json

JSON config format

{
  "scriptfile": "./my_script.js",
  "arg": {
    "key1": "value1",
    "key2": 42,
    "key3": true,
    "nested": {
      "sub": "value"
    }
  }
}
Field Type Description
scriptfile string Path to JS file (relative to the config folder or absolute)
arg object Arbitrary data available in the script as arg

Accessing arg in a script

All content of "arg" is passed into JS as a global object arg:

Config:

{
  "scriptfile": "./run.js",
  "arg": {
    "host": "smtp.office365.com",
    "port": 587,
    "recipients": ["admin@example.com", "ops@example.com"],
    "debug": false
  }
}

Script run.js:

console.log(arg.host);               // "smtp.office365.com"
console.log(arg.port);               // 587
console.log(arg.recipients[0]);      // "admin@example.com"
console.log(arg.debug);              // false

Paths in scriptfile

The path in scriptfile can be:

Format Example Behavior
Relative "./script.js" Relative to the config folder
Absolute "C:\\scripts\\run.js" Absolute path

Recommendation: Keep the config and script in the same folder and use "./script.js".


Project structure

Recommended file organization:

my-project/
├── config.json        ← config (passed to JsN.exe)
├── script.js          ← main script
└── lib/
    └── helpers.js     ← helper functions (if needed)

Multiple configs for different tasks

You can have multiple configs for one script with different parameters:

monitor/
├── monitor.js                  ← shared script
├── monitor-production.json     ← config for prod
└── monitor-staging.json        ← config for staging

monitor-production.json:

{
  "scriptfile": "./monitor.js",
  "arg": {
    "service": "MyApp_Production",
    "process": "myapp.exe",
    "notify_url": "https://hooks.slack.com/services/PROD/..."
  }
}

monitor-staging.json:

{
  "scriptfile": "./monitor.js",
  "arg": {
    "service": "MyApp_Staging",
    "process": "myapp.exe",
    "notify_url": "https://hooks.slack.com/services/STAG/..."
  }
}

Scheduled execution (Task Scheduler)

For periodic execution use Windows Task Scheduler:

  1. Open Task Scheduler (taskschd.msc)
  2. Create a task → Actions → New
  3. Program: C:\tools\JsN\JsN.exe
  4. Arguments: C:\scripts\monitor\config.json
  5. Configure trigger (every N minutes, at startup, etc.)

Or via PowerShell:

$action = New-ScheduledTaskAction `
    -Execute "C:\tools\JsN\JsN.exe" `
    -Argument "C:\scripts\monitor\config.json"

$trigger = New-ScheduledTaskTrigger -RepetitionInterval (New-TimeSpan -Minutes 5) -Once -At (Get-Date)

Register-ScheduledTask -TaskName "JsN-Monitor" -Action $action -Trigger $trigger -RunLevel Highest

Running as administrator

The svc_* functions require administrator privileges. Ways to run:

Via shortcut: Right-click → Run as administrator.

Via Task Scheduler: When creating the task → Run with highest privileges.

Via PowerShell:

Start-Process "JsN.exe" -ArgumentList "config.json" -Verb RunAs

JsN.exe exit codes

Code Meaning
0 Script executed successfully
1 Failed to load config or JS file