In my TS app, i’ve added a node package and the package.json was automatically updated. How do I use the package either in a module or a view, i.e. the equivalent of the following in CloudCode:
const fs = require("fs");
So what you’ll want to do is use the import
statement.
Here is a quick example, let’s say I’ve added the lodash
package in my app via Oxide, to import it in my view.ts files and use it, you will do the following:
import _ from "lodash";
async function init () {
const users = await DB.user.all().toArray();
// Split the data in users array into two seperate arrays
const chunkedArray = _.chunk(users, 2);
// Expected output: [ [...], [...] ]
console.log(JSON.stringify(chunkedArray, null, 2));
}