0

私はにかなり慣れていないので、かなり使いやすいように思えますが、コマンドラインを使用して値を取得し、その値を別のパッケージまたは.js.

簡単に言えば、私はパッケージ ( akamai-ccu-purge) を使用して、ファイルを入力し、ネットワーク上でパージすることに成功しました。

パージしたいファイルを入力するようにユーザーに促し、それをパッケージで使用することで、より動的にしたいと考えています。

使用していくつか試した後、var stdin = process.openStdin();実際に別のnpmパッケージを見つけましPromptた。ただし、どちらの方法でも同じ問題があるようです。

ノードは入力のために停止したくないようです。最初にそのモジュールを呼び出したにもかかわらず、入力を待たずに自動的にパージを行いたいようです。実際にファイルを入力する必要があるところまで到達しますが、待機しません。

ここでの理解または使用法に間違いなく何かが欠けています。何が間違っていますか?

これまでの私のコードは次のとおりです。

var purgeUrl = require('./getUrl2');  

var PurgerFactory = require('../../node_modules/akamai-ccu-purge/index'); // this is the directory where the index.js of the node module was installed

// area where I placed the authentication tokens 
var config = {
  clientToken: //my tokens and secrets akamai requires
};

// area where urls are placed. More than one can be listed with comma separated values 
var objects = [
  purgeUrl // I am trying to pull this from the getUrl2 module
];

// Go for it! 
var Purger = PurgerFactory.create(config);

Purger.purgeObjects(objects, function(err, res) {
  console.log('------------------------');
  console.log('Purge Result:', res.body);
  console.log('------------------------');
  Purger.checkPurgeStatus(res.body.progressUri, function(err, res) {
    console.log('Purge Status', res.body);
    console.log('------------------------');
    Purger.checkQueueLength(function(err, res) {
      console.log('Queue Length', res.body);
      console.log('------------------------');
    });
  });
});

モジュールは次のgetUrl2ようになります。

var prompt = require('../../node_modules/prompt'); 
  // 
  // Start the prompt 
  // 
  prompt.start();

  // 
  // Get property from the user 
  // 
  prompt.get(['newUrl'], function (err, result) {
    // 
    // Log the results. 
    // 
    console.log('Command-line input received:');
    console.log('  http://example.com/custom/' + result.newUrl);
    var purgeUrl = 'http://example.com/custom/' + result.newUrl;
    console.log(purgeUrl);
    module.exports = purgeUrl;
  });

助けてくれてありがとう!

4

2 に答える 2