Quickstart: Run any Blockspring function with Node.js.

In this tutorial, we'll learn how a single line of Node.js gets you access to all of the powerful utilities, algorithms, API calls, visualizations (and more) in the Blockspring community library.


First, install Blockspring. From your command line, enter:

npm install blockspring

Blockspring is installed. To initialize it, open your Node.js environment and enter:

var blockspring = require("blockspring");

Your first run: personal assistant.

Let's chat with a personal assistant.

blockspring.runParsed("personal-assistant-jeannie", {
  message: "What's the weather like in Antarctica today?"
}, function(res) { console.log(res.params["answer"]); })

Unless it's the end of the world, you'll probably find out that Antarctica is pretty cold right now:

It is currently clear, -3 Fahrenheit

You ran your first Blockspring function. Let's explain how that worked.

Blockspring functions in a nutshell

When you ran blockspring.runParsed, here's what happened:

  1. Blockspring used your function name to find Personal Assistant, a simple API call to the Jeannie personal assistant, written in Python, and submitted by user pkpp1233.

  2. Personal Assistant quickly executed in the cloud, with your message passed through as an input argument.

  3. You got back results and printed the printed the response, found in params["answer"].

That instant replay should raise some questions. Let's answer them.

A quick Q+A

Where do I find more Blockspring functions?
Browse the community library to find utilities, algorithms, API calls, visualizations, and more. You're now a quick search away from programming just about anything.

Great, I found a function. How do I run it?
Click "Integrations" on the function's homepage, choose Node, and copy and paste the given code snippet to wherever you need it. Try it yourself with Personal Assistant.

How do I know what inputs my function requires?
Again, click Personal Assistant, go to "Integrations", click Node, and you'll see in the given code snippet the only input required is message. The snippets are helpful for finding a function's required input arguments.

How do I know where to find the function output?
The output is found in the result's res.params. Explore that variable to find the output you're looking for. To learn more about the response, visit the api reference.

How do I create my own Blockspring function?
Visit the next Node.js quickstart to learn how to add your own function to Blockspring.

Your second run: interactive google map

Let's create an interactive Google map with Blockspring.

blockspring.runParsed("interactive-google-map", {
  locations: [
    ["Latitude", "Longitude", "Tooltip"],
    [37.4217542234, -122.100920271, "Somewhere"],
    [41.895964876906, -87.632716978217, "Out"],
    [28.58230778, 77.09399505, "There"]
}, function(res){

You should see this response printed out:


This function saves the interactive Google map as an HTML file to a temporary directory on your machine, and sets that location to res.params["map"]. That means you can open map as you would open any HTML file.

Go to your terminal and copy/paste the filepath you saw in res.params["map"] (remember - your filepath will be different) like so:

# remember - your path will be different!
open /var/folders/6w/920995kj30d_tn8skl8ml5wr0000gn/T/tmp-894623rk6q3k-map.html

You should see an interactive map open in your browser that looks like the image below:

Nodejs quickstart gmap

Your third run: summarize a URL

This time, let's summarize a URL in a line of Node.js.

To use Blockspring in your apps, you'll want to . Doing so guarantees you 100k function runs per month for free! now and we'll show you how to include it in your function below.

We'll also enable caching. If the summarization was done within the last 3,600 seconds, you'll receive it right away instead of needing to re-run the function.

blockspring.runParsed("summarize-text", {
  url: "http://www.usatoday.com/story/life/music/2015/04/18/rock-hall-of-fame-2015-induction-ceremony/25913423/",
  sentences: 1
}, {
  cache: true,
  expiry: 3600
}, function(res){

You should see this response printed out:

Such was the case Saturday night at the 30th annual gathering, which saw the inductions of Ringo Starr, Bill Withers, Joan Jett and the Blackhearts, Stevie Ray Vaughan & Double Trouble, the Paul Butterfield Blues Band, Green Day, Lou Reed and the "5'' Royales.

Become a Blockspring pro

Blockspring lets you program just about anything with a single line of Node.js and you're well on your way. You now know how to:

You can also add your own public (or private) functions to Blockspring. Any function you add to Blockspring can be easily run across languages, chained, composed, cached, and shared with others, without any set up or maintenance. Check out the next quickstart tutorial to learn how to create your first Blockspring function.

Discover new functions Work at Blockspring