Is there a way I could access app.js from a CloudCode task? I have a giant data structure that I would like to access. The other alternative would be to copy this data structure into the CloudCode task which I have done and it does work, but this would require me to update this data structure in two places, not one.
@alex.dang Unfortunately it is not possible to access app.js from CloudCode. The request has been noted as a feature request though.
Some context as to why not (at least not yet)? - In short, the app.js code expects to be executed in the context of a View and is also able to be executed offline (for example you can access your current view variables from app.js) , and that would not be the case for CloudCode. So if we just exposed the app.js file to CC it would be simple enough to run into runtime context errors. Furthermore, CC JS runs ES6 and async whereas app.js is executed synchronously via Stratified JS
So, at the moment your options are
move the app.js code to CloudCode instead (at least the parts that you also want access to in CC) and always execute it from CC
Use a TS app and move all the shared code to a NPM package that you include in both CC and the App
Move the data structure to the DB (I guess your logic would still be in two places though, so not so ideal)
If we do get the feature shipped it will likely not be available for existing JS apps but rather only for TS apps (due to the asynchronous nature of CC vs synchronous nature of the JS runtime)