javascript - 当我运行 Node js时收到错误: SyntaxError: Unexpected token '<'

标签 javascript node.js api authentication syntax-error

我正在尝试使用以下代码连接到我的API,我使用节点filename.html运行API attunication登录javascript代码。它显示以下错误。 Binance API Doc。拜托,有什么建议吗?

SyntaxError: Unexpected token '<'
←[90m    at wrapSafe (internal/modules/cjs/loader.js:1054:16)←[39m
←[90m    at Module._compile (internal/modules/cjs/loader.js:1102:27)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:986:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:879:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)←[39m
←[90m    at internal/main/run_main_module.js:17:47←[39m
API登录代码:
<html>
<script type="text/javascript" src="crypto-js.js"></script>
<script>
    
    var burl = 'https://api.binance.com';
    var endPoint = '/api/v3/account';
    var dataQueryString = 'recvWindow=20000&timestamp=' + Date.now();
    
    var keys = {
        'akey' : 'xxxxxxxx',
        'skey' : 'xxxxxxxx'
    }
    
    var signature = CryptoJS.HmacSHA256(dataQueryString ,keys['skey']);
    
    var ourRequest = new XMLHttpRequest();
    
    var url = burl + endPoint + '?' + dataQueryString + '&signature=' + signature;
    
    ourRequest.open('GET', url, true);
    ourRequest.setRequestHeader('X-MBX-APIKEY',keys['akey']);
    
    ourRequest.onload = function(){
        ourData = JSON.parse(ourRequest.responseText);
        console.log(ourData);
    }
    ourRequest.send();
    
    
</script>
</html>
crypto-js.js文件:
https://drive.google.com/file/d/1ZB5zTCpaz2M_01KcOZa1HLWDtAQOlKQ3/view?usp=sharing

最佳答案

转到项目文件夹并运行npm init -ynpm i crypto-js --save,然后执行以下步骤:

  • 创建一个filename.js文件
  • const CryptoJS = require('crypto-js')
  • 在此行
  • 之后包含您在脚本标记之间编写的逻辑
  • 使用命令node filename.js
  • 在命令行中运行它

    关于javascript - 当我运行 Node js时收到错误: SyntaxError: Unexpected token '<' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64106871/

    相关文章:

    javascript - 水平对齐 Chart.js y 轴

    mysql - 查询不存在的记录,返回 null,HTTP 200

    c - Lua API 计算变量名而不是值

    node.js - typescript 导入文件夹

    php - 自定义模块是在 Drupal 中访问外部 API 的最佳方式吗?

    javascript - 当我将随机数生成器/猜测器放入函数中时,我的 JavaScript 代码崩溃了。为什么会崩溃?

    javascript - VS Code 自动格式化更漂亮

    javascript - 为什么 JQuery 状态回调参数是字符串而不是数字?

    node.js - 将 outdir 中 ng build 生成的工件复制到另一个文件夹

    javascript - 准备一个函数以在生成器运行器中重复使用