This is a simple development environment for creating and testing Javascript code that can be used in the Glide Code Sandbox.
This sandbox allows you to write a JavaScript function that:
- Takes a JSON object as input
- Returns a JSON object as output
- Can use the NPM packages that come with the sandbox
- Can be easily tested
This environment is friendly to coding agents like Claude Code, so just run it and tell it what kind of code you need. It'll figure it out. Once it's done, copy/paste the code in code.js into the plugin. You can ignore the rest of this document unless you want to develop manually.
- Install dependencies:
npm install-
Edit
code.jsto implement your logic in therunfunction -
Test your code:
npm test- Run your code with custom input:
npm start -- '{ "your": "input" }'Your code.js file can import and use these packages:
lodash- Utility librarydate-fns- Date manipulationms- Time string conversionuuid- UUID generationfast-deep-equal- Deep equality checking
π¨ NEVER HARDCODE SECRETS IN YOUR CODE! π¨
API keys, tokens, passwords, and any sensitive data MUST ONLY be stored in .env files and accessed via process.env. NEVER write secrets directly in code.js or any other code file!
β WRONG - NEVER DO THIS:
// DANGER! This exposes your secrets! const apiKey = 'sk-1234567890abcdef'; // β NO! const password = 'mySecretPassword'; // β NO!β CORRECT - ALWAYS DO THIS:
// Safe! Secrets stored in .env file const apiKey = process.env.API_KEY; // β
YES! const password = process.env.PASSWORD; // β
YES!- Create a
.envfile in the project root (see.env.examplefor reference):
API_KEY=your_secret_api_key_here DATABASE_URL=postgres://localhost/mydb- Access them in your
code.js:
export async function run(input) { const apiKey = process.env.API_KEY; const dbUrl = process.env.DATABASE_URL; // Use your secrets safely return { authenticated: !!apiKey }; }Important:
.envis already in.gitignore- it will NEVER be committed to version control- Use
.env.exampleto document which variables are needed (without actual secret values) - When deploying to Glide, configure these secrets in the Glide environment
- NEVER EVER put actual secret values in code files!
Throw exceptions to signal errors - Glide will automatically retry!
When your code throws an exception, Glide treats it as an error and will automatically retry the operation. This means you can simply throw exceptions when something goes wrong, and Glide handles the retry logic for you.
export async function run(input) { const response = await fetch('https://api.example.com/data'); // Just throw an exception if something goes wrong if (!response.ok) { throw new Error(`API request failed: ${response.status} ${response.statusText}`); } return { data: await response.json() }; }Key points:
- Throw exceptions to signal errors
- Glide automatically retries when exceptions are thrown
- The dev environment will catch and display exceptions with helpful messages
- No retry logic needed in your code - Glide handles this automatically
code.js- Your main implementation (edit this!)code.test.js- Test suite for your coderunner.js- CLI runner (don't modify)package.json- Project configuration
The code.js file must export an async function named run:
export async function run(input) { // Your logic here // input is a JSON object // return a JSON object return { result: "your output" }; }import _ from 'lodash'; export async function run(input) { return { uppercased: _.upperCase(input.text), timestamp: new Date().toISOString() }; }Run it:
npm start -- '{ "text": "hello world" }'Tests use Node's built-in test runner. Add your tests to code.test.js:
import { test, describe } from 'node:test'; import assert from 'node:assert'; import { run } from './code.js'; describe('my tests', () => { test('should work correctly', async () => { const result = await run({ input: 'test' }); assert.strictEqual(result.output, 'expected'); }); });Run tests:
npm test- Only
code.jscan be modified for your implementation - The function must be named
runand must be exported - Only the specified packages are available
- No other code files can be imported
- Input and output must be JSON-serializable objects
# Simple input npm start -- '{ "name": "Alice" }' # Complex input npm start -- '{ "users": ["Alice", "Bob"], "active": true, "count": 42 }' # Run tests npm testAll console.log() statements in your code.js will output to the console, making debugging easy.