-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch-filename.js
49 lines (41 loc) · 976 Bytes
/
fetch-filename.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var express = require('express');
var app = express();
const testFolder = './kml-files/';
const fs = require('fs-readdir-promise');
var f = require('fs');
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
var fileName = [];
var j=0;
fs(testFolder)
.then(function(files) {
files.forEach(file => {
fileName[j++] = file;
})
})
.catch(function(err) {
console.log(err.message);
});
f.watch("./kml-files", { persistent: true }, function (event, filename) {
fileName=[];
fs(testFolder)
.then(function(files) {
j=0;
files.forEach(file => {
fileName[j++] = file;
})
//console.log(fileName);
})
.catch(function(err) {
console.log(err.message);
});
});
app.get('/', function(req,res) {
res.send(fileName);
});
app.listen('3030', function() {
console.log('Running on port 3030');
});