Last active
August 29, 2015 14:00
-
-
Save czy88840616/11171307 to your computer and use it in GitHub Desktop.
依赖request模块
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
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); | |
} | |
}); | |
} |
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
//用户内容 | |
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