Created
January 13, 2017 21:55
-
-
Save tmamedbekov/0814c274e1d4683e88b87cb53bac2978 to your computer and use it in GitHub Desktop.
Simple readdir with express server. NODE.JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var fs = require('fs'); | |
var app = express(); | |
app.get('/logJson', function (req, res) { | |
const logsFolder = '/folder/path/'; | |
fs.readdir(logsFolder, (err, files) => { | |
if (err) { | |
res.send("[empty]"); | |
return; | |
} | |
var lines = []; | |
files.forEach(function(filename) { | |
var logFileLines = fs.readFileSync (logsFolder + filename, 'ascii').toString().split("\n"); | |
logFileLines.forEach(function(logFileLine) { | |
if(logFileLine.match(/.*KEYWORD*./)) { | |
lines.push(logFileLine+'\n'); | |
} | |
}) | |
}) | |
============== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment