Skip to content

Instantly share code, notes, and snippets.

@czy88840616
Last active August 29, 2015 14:00
Show Gist options
  • Save czy88840616/11171307 to your computer and use it in GitHub Desktop.
Save czy88840616/11171307 to your computer and use it in GitHub Desktop.
依赖request模块
var util = require('util'),
vm = require('vm'),
fs = require('fs');
vm.runInNewContext(fs.readFileSync('user.js'), {
requestUrl: requestUrl
}, 'myfile.vm');
function requestUrl(url, callback) {
require('request')(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body);
callback(data);
//TODO
console.log('complete, and data.test=' + data.test);
}
});
}
//用户内容
requestUrl('https://raw.githubusercontent.com/czy88840616/avalon-node/master/package.json', function(data) {
//修改数据
data.test = 1;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment