- Notifications
You must be signed in to change notification settings - Fork0
glideapps/code-sandbox-playground
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a simple development environment for creating and testing Javascript code that can be used in theGlide 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 incode.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 therunfunctionTest your code:
npmtest- Run your code with custom input:
npm start --'{ "your": "input" }'Yourcode.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 viaprocess.env. NEVER write secrets directly incode.js or any other code file!
❌ WRONG - NEVER DO THIS:
// DANGER! This exposes your secrets!constapiKey='sk-1234567890abcdef';// ❌ NO!constpassword='mySecretPassword';// ❌ NO!
✅ CORRECT - ALWAYS DO THIS:
// Safe! Secrets stored in .env fileconstapiKey=process.env.API_KEY;// ✅ YES!constpassword=process.env.PASSWORD;// ✅ YES!
- Create a
.envfile in the project root (see.env.examplefor reference):
API_KEY=your_secret_api_key_hereDATABASE_URL=postgres://localhost/mydb
- Access them in your
code.js:
exportasyncfunctionrun(input){constapiKey=process.env.API_KEY;constdbUrl=process.env.DATABASE_URL;// Use your secrets safelyreturn{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 willautomatically retry the operation. This means you can simply throw exceptions when something goes wrong, and Glide handles the retry logic for you.
exportasyncfunctionrun(input){constresponse=awaitfetch('https://api.example.com/data');// Just throw an exception if something goes wrongif(!response.ok){thrownewError(`API request failed:${response.status}${response.statusText}`);}return{data:awaitresponse.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
Thecode.js file must export an async function namedrun:
exportasyncfunctionrun(input){// Your logic here// input is a JSON object// return a JSON objectreturn{result:"your output"};}
import_from'lodash';exportasyncfunctionrun(input){return{uppercased:_.upperCase(input.text),timestamp:newDate().toISOString()};}
Run it:
npm start --'{ "text": "hello world" }'Tests use Node's built-in test runner. Add your tests tocode.test.js:
import{test,describe}from'node:test';importassertfrom'node:assert';import{run}from'./code.js';describe('my tests',()=>{test('should work correctly',async()=>{constresult=awaitrun({input:'test'});assert.strictEqual(result.output,'expected');});});
Run tests:
npmtest- 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 inputnpm start --'{ "name": "Alice" }'# Complex inputnpm start --'{ "users": ["Alice", "Bob"], "active": true, "count": 42 }'# Run testsnpmtest
Allconsole.log() statements in yourcode.js will output to the console, making debugging easy.
About
Simple development environment for the Glide Code Sandbox
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.