Run in app snippets

These snippets need the Run in app toggle on the Write javascript step, so the code runs inside the axiom.ai desktop app rather than the page. That gives it Node.js APIs and the chatGPT() helper, at the cost of page access and console output; the Run in app notes cover the trade-offs. Puppeteer snippets, which also run in the app, have their own section.

Read a local file


The fs module lets an automation read and write files on the local machine. The step uses promises, while fs uses callbacks, so wrap the call in a promise for await to work:

let result = await new Promise(resolve => {
  fs.readFile('/Users/joe/test.txt', 'utf8', (err, data) => {
    if (err) {
      resolve([[err.message]]);
    } else {
      resolve([[data]]);
    }
  });
});
return result;

The file's contents are available in the code-data token. For a full reference, see the Node.js fs documentation.

Call ChatGPT directly


When the Extract data with ChatGPT and Generate text with ChatGPT steps do not fit, call ChatGPT from JavaScript with the built-in chatGPT() helper:

const key = '<API_KEY>';
const prompt = 'Write a short introduction to browser automation.';

let result = await chatGPT(key, prompt);
return [[result]];

Get an API key from your OpenAI account.