节点解析错误:返回时意外的令牌
Node Parsing Error: unexpected token when returning
我试图向映射数组返回一个值,这个值的名称是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)};
相关文章:
- React JS:未捕获(在承诺中)语法错误:在位置 0 的 JSON 中意外<令牌
- jQuery$.getJSON抛出意外令牌
- 为什么我在下面的..of循环中得到意外令牌
- 组件中的ReactJS意外令牌
- AngularJS $http GET 请求到本地 JSON 文件返回语法错误:意外令牌]
- 巴别塔,意外令牌 (15:33) ::.
- Sencha 2.0 和 Codeigniter RESTful API 生成未捕获的语法错误:意外令牌:
- 在事件上使用 jquery 时出现意外令牌
- JSON 中位置 4 处的意外令牌<
- 意外令牌 ) 在我的代码中
- Electron 和 Babel 6 异步/等待抛出意外令牌
- “JSON.parse(str)”返回“意外令牌c”,但str是一个字符串
- jQuery after() uncatch SyntaxError: 意外令牌 ILLEGAL
- 使用节点javascript的意外令牌ILLEGAL
- Javascript/JQuery-Chrome意外令牌
- Ajax 帖子未捕获语法错误:意外令牌非法
- angularjs-SyntaxError:请求从服务器返回时出现意外令牌
- jquery:使用ember的意外令牌C
- React本机项目中的意外令牌
- 解析有效的 JSON 得到“语法错误:意外令牌非法”