Testim gives you the flexibility to create a reusable action or validation made out of custom (JS) code.
You can either run the code inside the browser, or outside the browser (in the context node.js).
When to run in the browser
The advantage of executing the code inside the browser is that you can interact with the DOM (Testim can also find them for you using the smart locators), and that network requests (API) are probably already authenticated (cookies are passed automatically).
When to run in Node.js
The advantage of running the code outside the browser is that there are no CORS limitations, and you can use any NPM package you'd like, so accessing your DB becomes super easy.
Updated about a year ago