-
-
Save guibot17/ca9cfee0db8f5b9fce9348d296ae12c6 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