這樣做tutorial,我不希望使用device.js
只是把一行在它:module.exports = "<a1 ..
如何避免在node.js中使用模塊?
怎麼可以把這個設備ID在我的主腳本,並把它傳遞給apnagent
對象?試過這個,但我想這就是爲什麼連接沒有建立。
也許而不是module.exports = "<388 ..
我需要類似agent.set('something', and here the device ID);
?
var pfx = '/var/lib/openshift/555dd1415973ca1660000085/app-root/runtime/repo/pfx.p12';
module.exports = "<38873D3B 0D61A965 C1323D6C 0A9F2866 D1BB50A3 64F199E5 483862A6 7F02049C>"; // <----- THIS HERE
var apnagent = require('apnagent')
var agent = module.exports = new apnagent.Agent();
agent.set('pfx file', pfx);
// our credentials were for development
agent.enable('sandbox');
console.log('LOG1');
console.log(agent);
agent.connect(function (err) {
console.log('LOG2');
// gracefully handle auth problems
if (err && err.name === 'GatewayAuthorizationError') {
console.log('Authentication Error: %s', err.message);
process.exit(1);
}
// handle any other err (not likely)
else if (err) {
throw err;
}
// it worked!
var env = agent.enabled('sandbox')
? 'sandbox'
: 'production';
console.log('apnagent [%s] gateway connected', env);
});
也許有幫助:[Node.js module.exports的用途是什麼?你如何使用它?](http://stackoverflow.com/questions/5311334/what-is-the-purpose-of-node -js-module-exports-how-do-you-use-it) –