I'm trying to read directory that has some image files from Node.js and utilize the data in angularjs but I'm not sure my readdir is correctly working.
here's my server.js code
'use strict';
const express = require('express');
const fs = require('fs');
const app = express();
const http = require('http');
const path = require('path');
const port = process.env.PORT || 8000;
const server = http.createServer(app);
app.use(express.static(path.join(__dirname, '../client')));
app.get('/api/loadAll', function(req, res) {
fs.readdir(path.join(__dirname, '../client/assets'), function(err, imgs) {
if (err) { throw err; }
console.log('imgs', imgs);
res.send(imgs);
});
});
server.listen(port, function() {
console.log('Listening on port ' + port);
});
and here's my angularjs factory which receives from '/api/loadAll'
'use strict';
angular.module('app.service', [])
.factory('Images', function($http) {
var loadAll = function() {
return $http({
method: 'GET',
url: '/api/loadAll'
})
.then(function(res) {
console.log('res', res);
return res;
});
}
return {
loadAll: loadAll
};
});
hope these blocks of code are enough information to see what I'm doing wrong.
Thanks in advanced!!