JavaScript
1995fragletwebimperativefunctionalevent-driven.js.mjs.jsx
docker run --rm --platform="linux/amd64" 100hellos/javascript:latest
MCP + fragletc
MCPstdinargs
This language supports code execution via MCP and the fragletc CLI. Stdin piping and argument passing are both supported.
Install fragletc →This container runs a simple "Hello World!" program in JavaScript via Node.js.
Hello World
#!/usr/bin/env node
console.log("Hello World!")Coding Guide
Language Version
Node.js 20.x
Execution Model
- Interpreted, runs directly via Node.js
- Code executes at the top level
- Uses CommonJS module system by default
- ES modules available with
.mjsextension or"type": "module"in package.json
Key Characteristics
- Dynamic typing
- Case-sensitive
- Semicolons optional (ASI - Automatic Semicolon Insertion)
- Indentation is preserved from the injection point
Fragment Authoring
Write valid JavaScript statements or expressions. Your fragment becomes the script body. Code runs at the top level of the script.
Available Packages
Standard Node.js built-in modules are available:
fs- File system operationspath- Path manipulationhttp- HTTP server/clientcrypto- Cryptographic functionalityutil- Utility functionsos- Operating system utilitiesprocess- Process information and control
No additional npm packages are pre-installed. To use npm packages, you would need to install them (though this is typically not done in fraglet contexts).
Common Patterns
- Print:
console.log("message") - Variables:
const x = 10;orlet y = 20; - Functions:
function name() {}orconst name = () => {} - Arrays:
[1, 2, 3] - Objects:
{ key: "value" } - Template literals:
`Value: ${value}` - Arrow functions:
const add = (a, b) => a + b
Examples
// Simple output
console.log("Hello, World!");
// Function definition
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet("Alice"));
// Array processing
const numbers = [1, 2, 3, 4, 5];
const squared = numbers.map(x => x * x);
console.log(`Sum of squares: ${squared.reduce((a, b) => a + b, 0)}`);
// Object manipulation
const person = { name: "Bob", age: 30 };
console.log(`${person.name} is ${person.age} years old`);Caveats
- Fragments must be valid JavaScript that executes without errors
- Variables are scoped to the script level
- Use
console.log()for output (notprint()) - Remember that Node.js is the runtime, not a browser environment (no DOM APIs)
Fraglet Scripts
Array Reduce
#!/usr/bin/env -S fragletc --vein=javascript
const numbers = [1, 2, 3, 4, 5];
const squared = numbers.map(x => x * x);
const sum = squared.reduce((a, b) => a + b, 0);
console.log(`Sum of squares: ${sum}`);Echo Args
#!/usr/bin/env -S fragletc --vein=javascript
const args = process.argv.slice(2);
console.log("Args: " + args.join(" "));Stdin Upper
#!/usr/bin/env -S fragletc --vein=javascript
const fs = require("fs");
const input = fs.readFileSync("/dev/stdin", "utf8");
console.log(input.trim().toUpperCase());Test
#!/usr/bin/env -S fragletc --vein=javascript
console.log("Hello World!")Container Info
image100hellos/javascript:latest
build scheduleSunday
fragletenabled
sourcejavascript/files/