Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 我正在为CLI使用node,但每当我运行代码时,都会出现status 400错误 require(“dotenv”).config(); var-keys=require(“./keys.js”); const axios=require('axios'); 恒力矩=要求的(‘力矩’); var liriCommand=process.argv[2] 开关(liriCommand){ “本场音乐会”案例: 音乐会() 打破 案例y: //代码块 打破 违约: //代码块 } 函数concert(){ var-artist=''; var nodeArgs=process.argv; axios.get(“https://rest.bandsintown.com/artists/“+艺术家+”/events?app_id=codingbootcamp”) .然后(功能(响应){ 对于(变量i=3;i_Node.js_Axios_Command Line Interface - Fatal编程技术网

Node.js 我正在为CLI使用node,但每当我运行代码时,都会出现status 400错误 require(“dotenv”).config(); var-keys=require(“./keys.js”); const axios=require('axios'); 恒力矩=要求的(‘力矩’); var liriCommand=process.argv[2] 开关(liriCommand){ “本场音乐会”案例: 音乐会() 打破 案例y: //代码块 打破 违约: //代码块 } 函数concert(){ var-artist=''; var nodeArgs=process.argv; axios.get(“https://rest.bandsintown.com/artists/“+艺术家+”/events?app_id=codingbootcamp”) .然后(功能(响应){ 对于(变量i=3;i

Node.js 我正在为CLI使用node,但每当我运行代码时,都会出现status 400错误 require(“dotenv”).config(); var-keys=require(“./keys.js”); const axios=require('axios'); 恒力矩=要求的(‘力矩’); var liriCommand=process.argv[2] 开关(liriCommand){ “本场音乐会”案例: 音乐会() 打破 案例y: //代码块 打破 违约: //代码块 } 函数concert(){ var-artist=''; var nodeArgs=process.argv; axios.get(“https://rest.bandsintown.com/artists/“+艺术家+”/events?app_id=codingbootcamp”) .然后(功能(响应){ 对于(变量i=3;i,node.js,axios,command-line-interface,Node.js,Axios,Command Line Interface,} 我想要完成什么? *我试图阻止cli将每个argv作为其单独的值。。相反,我希望argv[3]等是一个字符串。。我已经在for循环中完成了这一点,但是我现在得到了一个status 400错误代码,我不知道如何利用这些信息来解决问题? 错误:请求失败,状态代码为400 *您正在将一个空字符串作为artist传递到URL中。400错误是HTTP请求错误,表示请求错误。问题是,您正在向无效URL发送请求,因为您将艺术家部分留空。在发出请求之前,您需要设置artist变量。您正在将一个空字符串作

}

我想要完成什么?
*我试图阻止cli将每个argv作为其单独的值。。相反,我希望argv[3]等是一个字符串。。我已经在for循环中完成了这一点,但是我现在得到了一个status 400错误代码,我不知道如何利用这些信息来解决问题?

错误:请求失败,状态代码为400
*

您正在将一个空字符串作为
artist
传递到URL中。400错误是HTTP请求错误,表示请求错误。问题是,您正在向无效URL发送请求,因为您将艺术家部分留空。在发出请求之前,您需要设置
artist
变量。您正在将一个空字符串作为
artist
传递到URL中。400错误是HTTP请求错误,表示请求错误。问题是,您正在向无效URL发送请求,因为您将艺术家部分留空。在发出请求之前,需要设置
artist
变量。
require("dotenv").config();
var keys = require("./keys.js");
const axios = require('axios');
const moment = require('moment');

var liriCommand = process.argv[2]




switch (liriCommand) {
case 'concert-this':
    concert()
    break;
case y:
    // code block
    break;
default:
// code block
}



function concert() {
var artist = '';
var nodeArgs = process.argv;
axios.get("https://rest.bandsintown.com/artists/" + artist + "/events?app_id=codingbootcamp")
    .then(function (response) {
        for (var i = 3; i < nodeArgs.length; i++) {

         artist = artist + ' ' + nodeArgs[i]

        }
        console.log(artist)
        console.log(response.data[0])
        console.log(response.data[0].venue.name)
        console.log(response.data[0].venue.city + ', ' + response.data[0].venue.region)
        console.log(moment(response.data[0].datetime).subtract(1, 'days').calendar())
    })