I’m using node.js to make a http request to a host. I found the latest version of node.js of 0.6.7 that make a request is like this
var http = require('http');
var req = http.request(options, function(res) {
var result ='';
res.on('data', function (chunk) {
//console.log('BODY: ' + chunk);
result += chunk;
});
res.on('end', function () {
console.log('end:' + result);
});
});
But I also found that the 0.3 version of node.js that make a request like this
http.createClient(80, 'api.t.sina.com.cn')
.request('GET', '/statuses/public_timeline.json?source=3243248798', {'host': 'api.t.sina.com.cn'})
.addListener('response', function(response){
var result = ''
response.addListener('data',function(data){
result += data
})
.addListener('end',function(){
tweets = JSON.parse(result)
})
})
But the 0.3 version of ‘createClient’ api is deprecated in 0.6.7. And I don’t find any docs that describe this.
I’m worrying about the api will change in the future. That will make my code not run in the future.
Can anyone give me some advice? Thanks!
The API has and will change. That’s the caveat for using bleeding-edge tech, like Node. The only advice I can give is to update your code to use the latest API, after all it’s not changing that often, or just stick to a working version if you don’t have the resources to keep upgrading your code base.. I personally keep my Node projects pretty small, that way upgrading is easier.
Also the use of NPM modules and generally modular code is encouraged. That way some API changes are easy update. Hope this helps. 🙂