I have logs files in server directory i wanted to display file names to client side so i have created readDirectory.js
that is reading names correctly Now i am very new to node.js
and i am trying to send json
data to client but its not happening, How can i send log files name to client using express ?
readDirectory.js
var fs = require('fs');
var path = './Logs'
var Logs = [];
function readDirectory(){
fs.readdir(path, function(err, items) {
Logs.push(items);
/* console.log(items);
for (var i=0; i<items.length; i++) {
console.log(items[i]);
}*/
});
return Logs;
}
exports.readDirectory = readDirectory;
app.js
var express = require('express');
var app = express();
var readDirectory = require('./readDirectory');
app.use(express.static(__dirname + "/public"));
app.get('/logs',function(req,res){
res.send(readDirectory.readDirectory());
});
angularFactory.js
angular.module('App').factory('DitFactory', function ($http) {
'use strict';
var data;
return {
data:"data from factory"
getLogs: function () {
return $http.get('/logs')
.then(function (response) {
return response.data;
});
}
}
});