我想发送给客户端文件名和文件创建日期,我尝试使用提供出生时间的 fs.stat 但我在那里没有看到文件名,所以我的问题是,出生时间是文件创建日期吗?
如何发送创建为 json 的文件名和日期?
应用程序.js
var readDirectory = require('./readDirectory');
app.get('/logs',function(req,res){
readDirectory.readDirectory(function(logFiles){
res.json(logFiles);
});
});
Run Code Online (Sandbox Code Playgroud)
读取目录.js
var fs = require('fs');
var path = './logs/ditLogs'
function readDirectory(callback){
fs.stat(path, function (err,stats) {
console.log('STATS',stats);
callback(stats);
});
}
exports.readDirectory = readDirectory;
Run Code Online (Sandbox Code Playgroud) 我看到使用带有ng-repeat angular指令的socket.io的一些性能问题,我从后端接收了大量数据,这会减慢应用程序的速度,因此在接收数据时我将无法点击任何内容.使用ng-repeat处理大型列表的最佳方法是什么,我们假设每分钟有1000条消息?
ctrl.js
$scope.event = [];
socket.on('ditConsumer', function(data) {
var obj = {
file: $scope.filename,
data: data
}
$scope.event.push(data);
}
Run Code Online (Sandbox Code Playgroud)
main.html中
<ul style="list-style: none;">
<li ng-repeat="message in event track by $index" ng-class="{lastItem: $last}"><span><strong>Log:</strong></span><span>{{message}}</span></li>
</ul>
Run Code Online (Sandbox Code Playgroud) 我正在动态加载数据到ng-repeat所以一旦我收到数据它没有绑定它ul
,我知道有时它会发生如果你有重复的索引但在下面的情况下我不知道发生了什么,任何想法?
main.html中
<div>
<ul ng-repeat="message in data track by index">
<li>{{message}}</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
ctrl.js
angular.module('loggingApp').controller('DitCtrl',function ($scope,DitFactory) {
'use strict';
DitFactory.getLogs().then(function (response) {
$scope.data = response.data;
console.log($scope.data);
});
});
Run Code Online (Sandbox Code Playgroud)
的console.log
printing data in console
["test.txt", "test1.txt", "test2.txt", "test3.txt", "test4.txt"]
Run Code Online (Sandbox Code Playgroud) 我有一个搜索功能,所以我有来自客户端的输入,Str
如果它与文件发送中的内容匹配作为响应.假设我Lorem
现在在文件中有文本,如果我lorem
从客户端搜索,它会因为区分大小写而发送空数组.我怎样才能使搜索案例不敏感?
searchService.js
var searchStr;
function readFile(str, logFiles, callback) {
searchStr = str;
// loop through each file
async.eachSeries(logFiles, function (logfile, done) {
// read file
fs.readFile('logs/dit/' + logfile.filename, 'utf8', function (err, data) {
if (err) {
return done(err);
}
var lines = data.split('\n'); // get the lines
lines.forEach(function(line) { // for each line in lines
if (line.indexOf(searchStr) != -1) { // if the line contain the searchSt
results.push({
filename:logfile.filename,
value:line
});
}
});
// …
Run Code Online (Sandbox Code Playgroud) 我试图将字符串推送到打字机数组,其抛出错误"无法推送到未定义",是正确的方式还是我需要使用扩展运算符?
api.ts
const api: IConfigName = {name: "getKey"};
const Name = "Web";
api.optionalParam.push(Name);
Run Code Online (Sandbox Code Playgroud)
IConfig.interface.ts
export interface IConfigName {
name: string;
optionalParam?: string[];
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试添加prehook,如果代码无法提交任何棉绒问题。什么是实现它的正确方法。
tslint.sh
#!/bin/sh
sh ./npm-install.sh
if [ $? -ne 0 ]; then
echo "npm-install error, exiting.."
exit 1
fi
echo "Running ts lint"
npm run lint
if [ $? -ne 0 ]; then
echo "Unit tests error, exiting.."
exit 1
fi
Run Code Online (Sandbox Code Playgroud) javascript ×5
node.js ×3
angularjs ×2
filesystems ×1
git ×1
ng-repeat ×1
performance ×1
search ×1
tslint ×1
typescript ×1