worker.js
const request = require('request');
function init() {
return ({url}) => {
return new Promise(resolve => {
request({url}, (error, response, body) => {
resolve(body);
});
});
}
}
module.exports = init;
main.js
const rpc = require('sync-rpc');
const client = rpc(__dirname + '/worker.js', 'My Server');
const result = client({url:'https://www.csdn.net'});
console.log(result);