YepCode JavaScript Code Rules
This file provides guidelines for LLMs to write JavaScript code compatible with YepCode platform and ready to use its specific helpers.
JavaScript Code Rules
Section titled “JavaScript Code Rules”Code Structure (JavaScript)
Section titled “Code Structure (JavaScript)”- Use NodeJS v20 features
- Wrap code in async function for await support
- Export functions using module.exports for modules
- Use ES6+ features when appropriate
Code Template (JavaScript)
Section titled “Code Template (JavaScript)”async function main() { // Access input parameters const { parameters } = yepcode.context;
// Your code here
// Return result return { message: "Success!" };}
module.exports = { main };Helpers Usage (JavaScript)
Section titled “Helpers Usage (JavaScript)”- Access execution info:
const { id, comment } = yepcode.execution; - Access process info:
const { id: processId, name: processName } = yepcode.execution.process; - Access schedule info:
const { id: scheduleId, comment: scheduleComment } = yepcode.execution.schedule; - Access team timezone:
const timezone = yepcode.execution.timezone; - Use environment variables:
const apiKey = process.env.API_KEY // (or yepcode.env.API_KEY); - Import YepCode modules:
const { myFunc } = yepcode.import("module-name");- Caution: you can’t use variables as module names, just hardcoded strings
- Import YepCode modules with specific version:
const { myFunc } = yepcode.import("module-name", "v1.0"); - Run another process:
await yepcode.processes.run("process-identifier", options);
Logging (JavaScript)
Section titled “Logging (JavaScript)”console.log("INFO message");console.debug("DEBUG message");console.info("INFO message");console.warn("WARNING message");console.error("ERROR message");Dependencies Management (JavaScript)
Section titled “Dependencies Management (JavaScript)”- You may use external npm packages
- Just add the require statement to the code and the package will be installed automatically
- If package import name is different than the package name, you must use the the add-package comment:
// @add-package axiosconst axios = require("axios");Local Disk (JavaScript)
Section titled “Local Disk (JavaScript)”const path = require("path");
// Calculate the path to the temporary fileconst filePath = path.join(process.env.TMP_DATA_DIR, "myfile.txt");
// Writing a fileconst fs = require("fs");fs.writeFileSync(filePath, "Hello from YepCode!");Datastore (JavaScript)
Section titled “Datastore (JavaScript)”// Setting a valueawait yepcode.datastore.set("key", "value");// Setting a object valueawait yepcode.datastore.set("key", JSON.stringify({ name: "John", age: 30 }));
// Getting a valueconst value = await yepcode.datastore.get("key");
// Deleting a valueawait yepcode.datastore.del("key");Storage (JavaScript)
Section titled “Storage (JavaScript)”const path = require("node:path");const localPath = path.join(process.env.TMP_DATA_DIR, "localfile.txt");
// Uploading a fileawait yepcode.storage.upload("path/myfile.txt", fs.createReadStream(localPath));
// Listing filesconst files = await yepcode.storage.list();
// Downloading a fileconst stream = await yepcode.storage.download("path/myfile.txt");stream.pipe(fs.createWriteStream(localPath));
// Deleting a fileawait yepcode.storage.delete("path/myfile.txt");Return Values (JavaScript)
Section titled “Return Values (JavaScript)”Standard Return
Section titled “Standard Return”return { message: "Success!" };Custom HTTP Status Codes
Section titled “Custom HTTP Status Codes”- This is the format for custom HTTP status codes:
return { status: 404, body: { "message": "Not found" }, headers: { "Content-Type": "application/json" }Transient Results (JavaScript)
Section titled “Transient Results (JavaScript)”return { transient: true, data: sensitiveData,};