executejavascript - Execute Javascript Code
Execute JavaScript code in a sandbox on our server. The following npm packages can be used: momentjs, cheerio, handlebars, ... (see https://1001fx.com for full list). Exceptions will be caught and returned. Strict is forced and imports are not allowed.
See Blog post for details
Examples:
Using Cheerio library to extract text from an HTML file Using Handlebars library to create HTML templates with dynamic data Using node-fetch library to retrieve data from an external API Using Yup library to validate user input data in a form.
Here are some examples for code:
Hints
- Remember that you need to return the result that you want to return.
- Add "const yourVariable = YOUR_INPUT_HERE;" to your script and fill in from previous steps in make.
- Use our playground to test your code before running it.
Playground
Available Packages
Case | NPM Package | URL |
---|---|---|
axios | axios | https://www.npmjs.com/package/axios |
cheerio | cheerio | https://www.npmjs.com/package/cheerio |
crypto-js | crypto-js | https://www.npmjs.com/package/crypto-js |
handlebars | handlebars | https://www.npmjs.com/package/handlebars |
joi | joi | https://www.npmjs.com/package/joi |
lodash | lodash | https://www.npmjs.com/package/lodash |
moment | moment | https://www.npmjs.com/package/moment |
moment-timezone | moment-timezone | https://www.npmjs.com/package/moment-timezone |
mustache | mustache | https://www.npmjs.com/package/mustache |
node-fetch | node-fetch | https://www.npmjs.com/package/node-fetch |
uuid | uuid | https://www.npmjs.com/package/uuid |
ulid | ulid | https://www.npmjs.com/package/ulid |
underscore | underscore | https://www.npmjs.com/package/underscore |
yup | yup | https://www.npmjs.com/package/yup |
zod | zod | https://www.npmjs.com/package/zod |
code
string
Code to be executed. Has to be valid javascript code. Store result in a variable and just write the variable in a single line at the end to return the value.
Example:
const a = 2; const b = 3;return a * b;