2014-11-02 58 views
0

嗨,我想用bash命令運行這個腳本。我已經安裝了節點從bash運行API javascript

我該如何運行?此外,我想解析bb.js NiceTitle一些變量例如節點./file.txt

<script type="text/javascript" src="http://binbox.io/api.js"></script> 
<script type="text/javascript"> 
    var BB = new Binbox.API("http://api.binbox.io/"); 
    BB.create({ 
     title: "here the NiceTitle from command", 
     text: "Here a path to ./file.txt", 
    }, function(result) 
    { 
     console.log(result); 

     if(result.ok) 
     { 
      console.log(result.id, result.salt); 
     } 
     else 
     { 
      console.log(result.error); 
     } 
    }); 
</script> 
+0

創建一個節點模塊,然後用'node '運行它。 – jfriend00 2014-11-02 21:52:33

回答

2

製作js文件與

var BB = new Binbox.API("http://api.binbox.io/"); 
BB.create({ 
    title: "here the NiceTitle from command", 
    text: "Here a path to ./file.txt", 
}, function(result) 
{ 
    console.log(result); 

    if(result.ok) 
    { 
     console.log(result.id, result.salt); 
    } 
    else 
    { 
     console.log(result.error); 
    } 
}); 

內容(例如file.js),那麼你就可以運行與

node file.js 

或從bash的

PS當然你需要在頂部包括庫文件

P.P.S.對於參數解析有process.argv http://nodejs.org/docs/latest/api/process.html#process_process_argv