2014-11-02 71 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