节点解析错误:返回时意外的令牌

Node Parsing Error: unexpected token when returning

本文关键字:意外 令牌 返回 点解 错误 节点      更新时间:2023-09-26

我试图向映射数组返回一个值,这个值的名称是latestDeploymentDate,但是,我收到一个解析错误,如标题所列。我想返回我使用ta.ago函数的最新部署的时间,但是,我收到一个解析错误,因为这个,我想创建一个单独的数组与时间,但似乎不能让这个工作。它需要这样返回,因为将有多个时间实例,需要返回这些实例才能输出。

    const express = require('express')();
    const request = require('request');
    const moment = require('moment');
    const ta = require('time-ago')();
    const webApplications = require('./XXX.json');

    express.listen(3000, function() {
      console.log('XXX...');
      express.get('/', function(req, res) {
        res.json(webApplications.map((item, latestDeploymentDate) => {
          res.setHeader('Access-Control-Allow-Origin', '*');
          res.setHeader('Access-Control-Allow-Headers', true);
          const newrequest = {
            url: `XXX`,
            headers: {
              'X-Api-Key': 'XXX'
            }
          }
          const gitlabRequest = {
            url: `XXX`,
            headers: {
              'PRIVATE-TOKEN': 'XXX'
            }
          }
          request(newrequest,(err, resp, body) => {
            const data = JSON.parse(body);
            const latestDeployment = data.deployments[0];
            latestDeploymentDate = new Date(latestDeployment.timestamp);
            //  console.log(latestDeploymentDate, laz1testDeployment);
            // res.json({latestDepoloyment: latestDeployment});
            //  return;
            request(gitlabRequest, (err, resp, body) => {
              const gitlabData = JSON.parse(body);
              const currentTag = latestDeployment.description;
              var currentIndex;
            console.log(`${item.appName}` + ' ');
            console.log(`Last deployed: ${latestDeployment.description}
              on ${moment(latestDeploymentDate).format('YYYY-MM-DD')}`);
              gitlabData.find((item, index) => {
                currentIndex = index;
                return item.name == currentTag
              });
              if (currentIndex > 3) {
${ta.ago(latestDeploymentDate)}`);
                console.log(`This ${currentIndex} was released ${ta.ago(latestDeploymentDate)}`);
                var deployedDate = ta.ago(latestDeploymentDate);
              } else {
${ta.ago(latestDeploymentDate)}`);
                var deployedDate = ta.ago(latestDeploymentDate);
                console.log(`This ${currentIndex} was released ${ta.ago(latestDeploymentDate)}`);
              }
              //  res.end();
            })
          })
          return {appName: item.appName, ta.ago(latestDeploymentDate)};
        }));
      });
    })

返回对象中缺少json键:

return {appName: item.appName, MYKEY: ta.ago(latestDeploymentDate)};