Created
November 29, 2020 15:11
-
-
Save butaji/6c67281fceee2cf5bb24412ddc1afef7 to your computer and use it in GitHub Desktop.
Вечерний Сниппет (node.js)
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 express = require('express') | |
const app = express() | |
const port = 3000 | |
app.get('/', (req, res) => { | |
res.send('Hello World!') | |
}) | |
app.get('/api', (req, res) => { | |
let files = list() | |
res.send({ | |
files: files | |
}) | |
}) | |
app.listen(port, () => { | |
console.log(`Example app listening at http://localhost:${port}`) | |
}) | |
const fs = require('fs'); | |
// directory path | |
const dir = './node_modules/'; | |
function list() { | |
// list all files in the directory | |
var arr = [] | |
try { | |
const files = fs.readdirSync(dir); | |
// files object contains all files names | |
// log them on console | |
files.forEach(file => { | |
arr.push(file); | |
}); | |
} catch (err) { | |
console.log(err); | |
} | |
return arr | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment