2016-11-16 19 views
1

このtutorialをやって、そして私はそれに1行を入れてdevice.jsを使用したくない:module.exports = "<a1 ..node.jsでモジュールを使用しないようにするにはどうすればよいですか?

enter image description here

はどのように私のメインのスクリプトでこのデバイス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); 
}); 
+1

おそらく役に立ちます:[Node.js module.exportsの目的は何ですか?どのように使用しますか?](http://stackoverflow.com/questions/5311334/what-is-the-purpose-of-node –

答えて

1

あなたはこれを試すことができます。

var pfx = '/var/lib/openshift/555dd1415973ca1660000085/app-root/runtime/repo/pfx.p12'; 
var deviceId = "<38873D3B 0D61A965 C1323D6C 0A9F2866 D1BB50A3 64F199E5 483862A6 7F02049C>"; // <----- THIS HERE 

var apnagent = require('apnagent') 
var agent = new apnagent.Agent(deviceId); 
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); 
}); 

説明はこれです:module.exportsは、共通のモジュール・エクスポートの構文です。このようにして、モジュールのエクスポートを避けて、コード内のdeviceIdを手動でハードコーディングすることによってインポートします。

+0

スクリプトはもともと 'device.js'と呼ばれていたので、' deviceId = 'または' device = 'を使うべきでしょうか? –

+0

これは変数の名前です。あなたはあなたが望む名前を使うことができます。 – pinturic

関連する問題