-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathechonest.js
More file actions
41 lines (35 loc) · 1.04 KB
/
echonest.js
File metadata and controls
41 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var http = require('http');
var querystring = require('querystring');
var echonest = function() {
var postData = querystring.stringify({
"api_key": process.env.ECHONEST_KEY,
"title": "Call Me Maybe",
"results": 1,
"sort": "artist_familiarity-desc"
});
var options = {
hostname: 'developer.echonest.com',
port: 80,
path: '/api/v4/song/search',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
}
};
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write(postData);
req.end();
}
module.exports = echonest;