简体   繁体   English

从bash运行API javascript

[英]Running API javascript from bash

Hi I would like to run this script with bash command. 嗨,我想使用bash命令运行此脚本。 I already installed node 我已经安装了节点

How can I run this? 我该如何运行? Also I would like to parse some variable example node bb.js NiceTitle ./file.txt 我也想解析一些变量示例节点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>

Make js file with 使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);
    }
});

content (for example file.js), then you can run with 内容(例如file.js),则可以使用

node file.js

or from bash 或从bash

PS Sure you will need require in the top to include lib PS当然,您需要在顶部包含lib的要求

PPS For arguments parsing there is process.argv http://nodejs.org/docs/latest/api/process.html#process_process_argv PPS对于参数解析,有process.argv http://nodejs.org/docs/latest/api/process.html#process_process_argv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM