Endpoint with Express

node v4.9.1
version: 4.0.0
endpointsharetweet
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) => { return res.send("hi") }) 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")) })
Use this helper to quickly return a RunKit Endpoint compatible express app, in place of calling express directly. Here's an example use: https://runkit.com/runkit/express-endpoint-demo.
Loading…

no comments

    sign in to comment