-4
マップされた配列に値を返そうとしていますが、この値の名前は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)};
}));
});
})
あなたはエラーのスタックトレースを投稿することができますか? –
/Users/jba71/last-app-web/server-copy-new.js:66 return {appName:item.appName、ta.ago(latestDeploymentDate)}; ^ SyntaxError:予期しないトークン。モジュール番号: をexports.runInThisContext(vm.js:53:16) (Module._compile(module.js:387:25)) Object.Module._extensions..js(module.js:422:10) at Module .load(module.js:357:32)Function.Module._load(module.js:314:12) Function.Module.runMain(module.js:447:10)起動時に (node.js :148:18) at node.js:405:3 – DaveDavidson