Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

My First Playground

node v14.20.1
version: 2.0.0
endpointsharetweet
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:
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.type("text/plain"); res.send("Hello World!"); }); app.get("/200", (req, res) => { var formData = { "status" : "200", "message" : "Everything works here!" }; res.type("application/json"); res.send(formData); }); app.get("/500", (req, res) => { var formData = { "status" : "500", "message" : "Nothing works here!" }; res.type("application/json"); res.send(formData); }); app.get("/codes/:code", (req, res) => { var code = req.params.code; var message = ''; if (code == "200") { message = "Success"; } else if (code == "500") { message = "Failure"; } var formData = { "status" : req.params.code, "message" : message }; res.type("application/json"); res.send(formData); });
Loading…

no comments

    sign in to comment