index rss mastodon twitter github linkedin email
Álvaro Ramírez
sponsor

Álvaro Ramírez

05 October 2015 Javascript fetch node sample

Playing with node and fetch:

// Requisite: npm install node-fetch --save
// Save to fetch-demo.js
// Run: node fetch-demo.js

var fetch = require('node-fetch');

fetch("http://xenodium.com/data/javascript-fetch-node-sample/message.json\n", {
  method: 'GET',
  timeout: 5000
}).then(function(response) {
  return response.json();
}).then(function(response) {
  console.log('subject: ' + response.subject);
  console.log('body: ' + response.body);
}).catch(function(reason) {
  console.log(reason);
});