Write a task

Define a task, a function in your project that does one job and returns a result, then run it with a payload: by hand, on a schedule or from a webhook.

Before you start

You need a project. See Create a project.

Write a task

  1. Add the task. Its file name is its ID:
    tasks/word-count.ts
    export default {  name: "word-count",  description: "Count the words in a text.",  schedulable: true,  async run({ input }) {    return { words: String(input.text).trim().split(/\s+/).length };  },};
  2. Run it on your machine. --config is the payload:
    Shell
    npx veryfront task word-count --config '{"text": "Veryfront runs agents, tasks and workflows"}'
  3. Read the result: it prints "words": 6.
  4. Start the project with npm run dev (Work locally) and open Building blocks > Tasks in Studio. You should now see word-count listed.

Try it in a sandbox

  1. Create a project

  2. Add the task

  3. Check it

Try it out

Next steps