-
-
Save sdras/f5665c5bcd98b48b4a3a9aed1312fd37 to your computer and use it in GitHub Desktop.
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
const http = require('http') | |
const hostname = '127.0.0.1' | |
const port = 3000 | |
//modified from this original: https://stackoverflow.com/questions/11194287/convert-a-directory-structure-in-the-filesystem-to-json-with-node-js/11194896 | |
function files() { | |
var fs = require('fs'), | |
path = require('path') | |
function dirTree(filename) { | |
var stats = fs.lstatSync(filename), | |
info = { | |
path: filename, | |
name: path.basename(filename) | |
} | |
if (stats.isDirectory()) { | |
info.type = 'folder' | |
info.children = fs.readdirSync(filename).map(function(child) { | |
return dirTree(filename + '/' + child) | |
}) | |
} else { | |
info.type = 'file' | |
} | |
return info | |
} | |
var util = require('util') | |
var output = dirTree('vue/') | |
return JSON.stringify(output) | |
} | |
const server = http.createServer((req, res) => { | |
res.statusCode = 200 | |
res.setHeader('Content-Type', 'text/plain') | |
res.end(files()) | |
}) | |
server.listen(port, hostname, () => { | |
console.log(`Server running at http://${hostname}:${port}/`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment