Would you like to clone this notebook?

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

Cancel

JSON Endpoint Example 2

node v4.9.1
version: 1.0.0
endpointsharetweet
Send a request like ?url=http://google.com, get back the title of the page.
var endpoint = require("@runkit/runkit/json-endpoint/1.0.0") var request = require("request") var cheerio = require("cheerio") endpoint(module.exports, function(req, done) { request(req.query.url, function(error, response, body) { if (error) return done({error: "could not retrieve page"}) var page = cheerio.load(body) done({ title: page("title").text() || "no title" }) }) })
Instead of promises, we're using callbacks, and explicitly calling "done" with whatever value we want to return to the caller.
Loading…

13 comments

  • posted 4 years ago by gentlejack
    In God I trust.
  • posted 3 years ago by dulgoffar87
    Saya ingin yang yang normal dan tidak ada unsur kesalan
  • posted 3 years ago by dannygriffin000
    https://npm.runkit.com/grunt-cli
  • posted a year ago by 5ef7a92aae52aa001939b3ac
    GGzGGaGaGazGazhGazh3Gazh3hGazh3hbGazh3hbnGazh3hbnxGazh3hbnxfGazh3hbnxfaGazh3hbnxfajGazh3hbnxfajlGazh3hbnxfajllGazh3hbnxfajllcGazh3hbnxfajllcnGazh3hbnxfajllcna
  • posted a year ago by 5ef7a92aae52aa001939b3ac
    UUzUzaUzabUzablUzablyUzably4Uzably4kUzably4klUzably4klgUzably4klglUzably4klglfUzably4klgl
  • posted a year ago by 0565447774f
  • posted 5 months ago by 60cc2c0b20365b001a0208f7
    http://google.com
  • posted 4 months ago by 6102df96c04d9a001b8b9359
    DONE
  • posted 3 months ago by mrrhak
  • posted 2 months ago by ggoldselleruk
    Gdzie gold
  • posted 12 days ago by quenly
    Junaini
  • posted 12 days ago by quenly
    Erliyanti
  • posted 12 days ago by quenly
    Ktp

sign in to comment