Created
February 13, 2016 23:39
-
-
Save rolfen/e83559873f0ece342412 to your computer and use it in GitHub Desktop.
node: Gets the list of files in a directory and serves it in JSON.
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 http = require('http'); | |
var fs = require('fs'); | |
var originalsPath = 'pics/originals'; | |
var originalFiles = {}; | |
fs.readdir('pics/originals',function(err, files){ | |
originalFiles = files; | |
}) | |
http.createServer(function (request, response) { | |
response.writeHead(200, { | |
'Content-Type': 'application/json', | |
'Access-Control-Allow-Origin' : '*' | |
}); | |
response.end(JSON.stringify({ | |
"originals" : { | |
"basePath" : originalsPath, | |
"fileList" : originalFiles | |
} | |
}, null, 2)); | |
}).listen(1337); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment