How to use fetch() in payload formatter javascript code?

Is it possible to make network requests in the javascript payload formatter code on TTN console?

I tried using fetch() but got some unknown error.

var fs = require('fs');
import fetch from "node-fetch";

Error:

SyntaxError: SyntaxError: (anonymous): Line 3:1 Unexpected reserved word (and 2 more errors)

If it is possible, what library should I use?

Thanks in advance

The JavaScript runtime for payload formatters does not support modules nor network access for security reasons: JavaScript | The Things Stack for LoRaWAN

You will have to find a simpler approach to implement your encoder/decoder.

1 Like