Skip to content

Instantly share code, notes, and snippets.

@guibot17
Forked from tmamedbekov/app.get
Created March 21, 2019 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guibot17/ca9cfee0db8f5b9fce9348d296ae12c6 to your computer and use it in GitHub Desktop.
Save guibot17/ca9cfee0db8f5b9fce9348d296ae12c6 to your computer and use it in GitHub Desktop.
Simple readdir with express server. NODE.JS
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