Last active
December 24, 2015 23:49
-
-
Save wolfeidau/6882870 to your computer and use it in GitHub Desktop.
NodeJS stdlib Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var url = require('url'); | |
var creds = require('./creds.js'); | |
var https = require('https'); | |
var scheme = 'https'; | |
var hostname = 'api.tempo-db.com'; | |
var baseUrl = scheme + '://' + hostname; | |
var auth = 'Basic ' + new Buffer(creds.key + ':' + creds.secret).toString('base64'); | |
var seriesKey = '1_D90343085872CA9C_687_0_2000'; | |
function uploadEntry(cb){ | |
var data = []; | |
data.push({t: new Date(), v: Math.random() * 50}); | |
var body = JSON.stringify(data); | |
var headers = { | |
Authorization: auth, | |
'Content-Type': 'application/json', | |
'Content-Length': body.length | |
}; | |
var opts = { | |
host: hostname, | |
port: 443, | |
path: '/v1/series/key/' + seriesKey + '/data/', | |
method: 'POST', | |
agent: false, | |
headers: headers | |
}; | |
// console.log('sending', data[0]); | |
var req = https.request(opts,cb); | |
req.on('error', function(e) { | |
console.err('error', e); | |
}); | |
req.write(body); | |
req.end(); | |
}; | |
function callback(result){ | |
console.log('statusCode', result.statusCode); | |
} | |
setInterval(uploadEntry.bind(null, callback), 1000); | |
setInterval(gc, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is master without the GC routine.