runkit's notebooks

  • Untitled - /runkit/folder-new
    Last edited a year ago
    const fs = require("fs"); // Make a new folder. fs.mkdirSync("my-new-folder"); // Verify that the folder is on the filesystem. fs.readdirSync("./").filter(aFile => aFile === "my-new-folder");
  • Untitled - /runkit/api-new
    Last edited a year ago
    exports.endpoint = function(request, response) { response.end("Hello world!"); }
  • Untitled - /runkit/api-new-express-post
    Last edited a year ago
    const express = require("express"); const app = express(); const port = 3000; // use body-parser to automatically parse JSON-encoded request bodies const bodyParser = require("body-parser"); app.use(bodyParser.json()); const helperMessage = { message: "Try posting JSON to this endpoint!" }; // add a helper message encouraging POSTing to this API app.get("/", (req, res) => res.json(helperMessage)); // listen for POST requests and respond based on that POSTed data app.post("/", (req, res) => { if (req.body.key) return res.send({ key: req.body.key }); return res.send({ message: `You posted ${JSON.stringify(req.body)}` }); }); app.listen(port, () => console.log(`Example API listening on port ${port}!`)); /* Try it out by POSTing to this endpoint! Get this API's URL from the Endpoint button at the top of the Notebook curl -X "POST" <ENDPOINT URL> \ -H 'Content-Type: application/json; charset=utf-8' \ -d #x27;{ "key": "value" }' */
  • My First Playground - /runkit/welcome
    Last edited a year ago
    This is a playground to test JavaScript. It runs a completely standard copy of Node.js on a virtual server created just for you. Every one of npm’s 300,000+ packages are pre-installed, so try it out:
  • One More Thing... - /runkit/one-more-thing
    Last edited 6 years ago
    const React = require("react"); const createReactClass = require('create-react-class'); module.exports = createReactClass( { render: function () { return React.createElement('div', {style: { font:"40px Georgia", textAlign:"center", background:"white"} }, [ "Oh, and we're hiring!", React.createElement('br'),React.createElement('br'), React.createElement('iframe', {src: "https://runkit.com/jobs", style: { width:"100%", height:"1200px", border:0, margin:0, padding: 0 }}) ]); } });
  • "acorn" require time - /runkit/acorn-require-time
    Last edited 6 years ago
    var child_process = require("child_process"); var request = require("acorn"); var path = require.resolve("acorn"); exports.endpoint = (req, res) => { var out = child_process.execSync(`node -e 'var x = new Date(); require("${path}"); console.log(new Date() - x);'`); res.end(out) }
  • "request" require time - /runkit/request-require-time
    Last edited 6 years ago
    var child_process = require("child_process"); var request = require("request"); var path = require.resolve("request"); exports.endpoint = (req, res) => { var out = child_process.execSync(`node -e 'var x = new Date(); require("${path}"); console.log(new Date() - x);'`); res.end(out) }
  • "babel-core" require time - /runkit/babel-core-require-time
    Last edited 6 years ago
    var child_process = require("child_process"); var request = require("babel-core"); var path = require.resolve("babel-core"); console.log(path) exports.endpoint = (req, res) => { try { var y = new Date(); child_process.execSync(`node -e 'require("${path}")'`); res.end((new Date() - y).toString()) } catch(e) { console.log(e); res.statusCode = 400; res.end("failed"); } }
  • Express-Endpoint Demo - /runkit/express-endpoint-demo
    Last edited 7 years ago
    var tonicExpress = require("@runkit/runkit/express-endpoint/1.0.0") // Just provide the exports object to the tonicExpress helper var app = tonicExpress(module.exports) var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false })); app.get("/", (req, res) => res.send("Hey!")) app.get("/:name", (req, res) => { res.send(`Hello ${req.params.name}!`) }) app.post("/echo-form", (req, res) => { var formData = Object.keys(req.body).map( k => `${k}: ${req.body[k]}` ) res.type("text/plain") res.send(formData.join("\n")) })
  • Telephone? - /runkit/telephone
    Last edited 7 years ago
    You probably played the game of telephone as a kid, but it's kind of boring as an adult. But what if we get the computer to play for us instead? First, let's require some utilities from other notebooks, and define a few of our own.